近一年一直在作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