jstl标签
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'testjstl.jsp' starting page</title> </head> <body> <jsp:useBean id="siqi" class="entity.Hero" /> <c:set target="${siqi}" property="name" value="骑士" /> 英雄名${siqi.name } <h1>一个条件 </h1> <c:if test="${10>50}"> <h1>这是jstl if</h1> </c:if> <h1>多重条件 </h1> <c:set var="num" value="4" /> <c:choose> <c:when test="${num>0}"> 星期一 </c:when> <c:when test="${num>3}"> 星期二 </c:when> <c:when test="${num>7}"> 星期三 </c:when> <c:otherwise> 星期4-7 </c:otherwise> </c:choose> <h1>循环</h1> <table border=1> <c:forEach var="i" begin="1" end="9"> <tr> <c:forEach var="j" begin="1" end="${i}"> <td>${i}* ${j}=${i*j } </c:forEach> </c:forEach> </table> <h1>集合测试</h1> <% ArrayList list=new ArrayList(); list.add("hello"); list.add("china"); list.add("world"); list.add("112233"); pageContext.setAttribute("citys",list); Map map=new HashMap(); map.put("n1","周玮"); map.put("n2","安敏"); map.put("n3","刘勇"); pageContext.setAttribute("names",map); %> <c:forEach var="yy" items="${citys}"> <h1> ${yy} </h1> </c:forEach> <hr/> <table border=1 width="300"> <tr> <td>学号</td> <td>键</td> <td>值</td> </tr> <c:forEach var="yy" items="${names}" varStatus="k"> <tr> <td>${k.index } <td>${yy.key} <td>${yy.value } </c:forEach> </table> <h1> 折分字符串</h1> <c:set var="tt" value="长沙,湘潭,株洲;美国;日本" /> <c:forTokens items="${tt}" delims=",;" var="obj"> ${obj}--- </c:forTokens> <hr/> <h1> url 重写</h1> <%-- String newurl= response.encodeRedirectURL("38jie.jsp"); response.sendRedirect(newurl); //跳 --%> <c:url var="nextpage" value="38jie.jsp"> <c:param name="stname" value="1111班jstl url重写测试" /> <c:param name="stpass" value="333" /> </c:url> <h1>${nextpage }</h1> <c:redirect url="${nextpage}" /> </body> </html>