JSTL學習筆記

配置JSTL
原文引入:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

core 標籤庫
1.<c:out>例:<c:out value="${execption}"/>
表達式輸出,類似於JSP中<%=%>,或EL中${el-execption}

2.<c:set>例:<c:set var="uername" value="lisi" scope="session"/>
設置範圍變量的值域,javabean對象屬性

3.<c:remove> 例:<c:remove var="uername" scope="session" />
相對於<c:set>,移除變量範圍

4.<c: catch> 
例:<c:catch var="execption">
      //...代碼
	</c:catch>
捕獲異常並保存到變量中

條件標籤
1.<c:if> <c:if test="${user.visitCount==1}"> 也可聲明var
//...代碼
</c:if>

2.<c:choose>、<c:when>、<c:otherwise>
eg:<c:choose>
		<c:when test="${execption}">
		//something...
		<c:/when>
		<c:when test="${execption}">
		//something...
		<c:/when>
		<c:otherwise>
		//something...
		<c:/otherwise>
   </c:choose>
   
迭代標籤
<c:forEach items="${用於迭代的集合}" var="迭代對象">
	//something...
</c:forEach>
固定次數
<c:forEach var="i" begin="100" end="110">
	${i}
</c:forEach>


格式標籤
<fmt:formatNumber value="12.3" pattern=".000"/> 
        輸出12.3000
<fmt:formatDate value="<%=new java.util.Date()%> type="date"/>
	輸出2007-5-21
<fmt:formatDate value="<%=new java.util.Date()%" type="time"/>
	輸出9:25:11
<fmt:formatDate value="<%=new java.util.Date()%" type="both"/>
	輸出2007-5-21 9:25:11
	
	
補充:
1.替換 request.getParameter("test"):
<c:if test="${param.test!=null}">
	<c:out value="${param.test}">
</c:if>

2.<c:redirect url="a.jsp">

3.<c:redirect url="/mas.jsp" >
	<c:param name="name1" value="665"/>
	<c:param name="name2" value="joho"/>
  </c:redirect>

4.<c:forTokens items="zhangsan:lils:as" delims=":" var="name">  
	${name}
  </c:forTokens>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章