近一年一直在作ANDROID的東西,最近待業,打算去面JAVA崗位,不得不從新溫習一下JSTL和struts標籤相關東西,怕萬一被面官問倒。
這裏作一下總結吧:
首先須要在JSP頁面中包含JSTL核心標籤庫
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
其次JSTL的經常使用標籤有:
java
<c:set>框架
<c:remove>jsp
<c:if>ide
<c:forEach > rem
<c:choose><c:when></c:when><c:otherwise></c:otherwise></c:choose>it
<c:out>class
用法舉例
1.<c:set var="square" value="${param['x'] }"/>
2.<c:remove var="square"/>
3.<c:if test="${not empty param['x']}">xxxxxxxxxx</c:if>
4.<c:forEach items="${entityList}" var="entity" [varStatus="varStatusName"]>
${entity.title}
</c:forEach>
5.<c:choose>
<c:when test="${not empty entity.title}">
${entity.title}
</c:when>
<c:otherwise>
unknow
</c:oherwise>
</c:choose>
6.<c:out value="${entity.title}" escapeXml="true"/>
struts標籤須要在頁面中包含:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
struts經常使用標籤:
1.<s:if test="empty entity.title">
${entity.title}
</s:if>
<s:else>
unknow
</s:else>
2.<s:iterator value="entityList">
${title}
${name}
</s:iterator>
小結:STRUTS的標籤代碼更爲精簡,可是JSTL做爲JSP的標準表達式語言具備不可替代的標準做用,它不依賴於STRUTS框架,因此本人多數仍是使用JSTL較多。
JSTL和struts寫法區別:
1.JSTL中當要用到某變量時須要使用${},而在struts表達式中則不用。
2.在循環中使用時STRUTS不用寫多級引用,代碼更爲簡練。
STRUTS標籤中還自帶了許多替代HTML元素的標籤,以及一些校驗的標籤,這裏再也不贅述。
附件爲 JSTL 和 struts標籤相關參考內容
test