日期:2014-05-16 浏览次数:20436 次
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>接着可以在页面上使用,如core标签:
<c:out value=“${expression}” default=“a”/> <c:set var=“str” value=“试下” scope=“session”></c:set>//设置某个范围如session属性的值 <c:set target=“bean实例” property=“” value=“”/>//设置某个bean成员变量的值 等同于 <jsp:setProperty property=“” value=“”/> <c:remove var=“” scope=“”/>//移除某个范围的变量要运行JSTL标签,需要jstl1.2.jar包
<c:import url="http://www.url.com/edit.js" var="newsfeed"/>将请求重新定向到http://www.yourname.com/login.jsp页,相当于response.setRedirect();
<c:redirect url="http://www.yourname.com/login.jsp"/>
<c:redirect url="login.jsp"><c:param name="id" value="888"/></c:redirect>将参数888以id为名字传递到login.jsp页面,相当于login.jsp?id=888
<% int score = 90; pageContext.setAttribute("score", score); %> <c:if test="${score>80}">优秀</c:if>
<% int score = 90; pageContext.setAttribute("score", score); %> <c:choose> <c:when test="${score<60}">不及格</c:when> <c:when test="${score<80}">及格</c:when> <c:otherwise>优秀</c:otherwise> </c:choose>
<% ArrayList aList = new ArrayList(); aList.add(23); aList.add(true); aList.add("ArrayList"); aList.add(new Date()); aList.add(3445652); pageContext.setAttribute("aList", aList); int size = aList.size(); pageContext.setAttribute("size", size); %> <c:forEach begin="0" end="${size}" var="i"> ${aList[i]} </c:forEach>
<% ArrayList aList = new ArrayList(); aList.add(23); aList.add(true); aList.add("ArrayList"); aList.add(new Date()); aList.add(3445652); pageContext.setAttribute("aList", aList); %> <c:forEach items="${aList}" var="i"> ${i} </c:forEach>