Core標簽庫
<%@ PRefix="c" uri="http://java.sun.com/jsp/jstl/core"%>一般用途的標簽1.<c:out>
把表達式的結果打印到網頁上
<c:out value="${param.name}"><c:out value="表達式" default=“默認值”><c:out value="表達式">默認值</c:out>//如果表達式為null,則輸出默認值2.<c:set>2.1為string變量設定值
<c:set var="變量名" value="值" scope="默認page"> 2.2為javaBean設定值<c:set target="javabean的id" property="屬性" value="值"> 2.3為Map賦值<c:set target="map id" property="key" value="value">3<c:remove>刪除特定范圍內的命名變量
<c:remove var="變量" scope="">4<c:catch>捕獲標簽主體異常,保存在頁面范圍
<c:catch var="ex">//有可能出異常的代碼</c:catch><c:out value="ex.message" default="no Exception">條件標簽1.<c:if>
<c:if test="表達式" var="表達式的值" scope=""><c:if test="${param.name='jack'}">只有test為true執行</c:if>2.<c:choose>,<c:when>,<c:otherwise><c:choose><c:when test=""></c:when><c:otherwise ></c:otherwise></c:choose>迭代標簽
1.<c:forEach>
<c:forEach var="name" items="集合" >${name}</c:forEach>1.1varStatus屬性count:當前元素在集合中的序號,從1開始計數index:當前元素在集合中的索引,從0開始計數first:是不是第一個last:是不是最后一個<c:forEach var="name" items="集合" varStatus="status">${name},${status.count},${status.index}</c:forEach>1.2 begin,end,step<c:forEach var="name" items="集合" varStatus="status" begin="1" end="3" step="2">${name},${status.count},${status.index}</c:forEach>//開始索引,結束索引,步長2<c:forTokens>分割字符串<c:forTokens var="name" items="字符串" delims="分隔符,比如冒號">${name}</c:forTokens>//其他屬性和forEach一樣URL相關標簽1.<c:import><c:import url="web資源url"/>不僅可以是本應用中的,也可以是其他web應用中的<c:import url="xxx.jsp"/><c:import url="/xxx/aaa.jsp"/><c:import url="http://xxxx/aa/bbb.jsp"/>context屬性包含同一個servlet容器下的其他web應用,不過crossContext==true<c:import url="aaa.jsp" context="bbb"/>var屬性把url內容輸出到var中然后${xxxx}來輸出2.<c:url> 按特定的規則重構url<c:url value="原來url" var="新的url變量" scope="" /><c:param>子標簽 name和value屬性,就是url后面帶的參數。會對特殊符號進行編碼3.<c:redirect>重定向<c:redirect url=""/>也有<c:param>子標簽 context屬性。
新聞熱點
疑難解答