JSTL(c标签)与Struts2(s标签)标签的常用功能对比
2015-09-27 12:23
666 查看
1. 条件标签 JSTL
像这样一个list,里面有3条记录,每条记录包含两个对象,我把结果集(lstRooms)request到了页面,想遍历显示RrmRooms里的id,和RrmRoomType里的name.
我用JSTL实现如下:
<c:if test="${user.password == 'hello'}"> <c:choose> <c:when test="${user.age <= 18}"> <font color="blue"/> </c:when> <c:when test="${user.age <= 30 && user.age > 18}"> <font color="red"/> </c:when> <c:otherwise> <font color="green"/> </c:otherwise> </c:choose> </c:if>STRUTS2:
<s:if test="#user.age <= 18"> <font color="blue"/> </s:if> <s:elseif test="#user.age <= 30 && user.age > 18"> <font color="red"/> </s:elseif> <font color="green"/> </s:else>2. 迭代标签JSTL:
<c:forEach var="user" items="${users}"> <c:out value="${user.userName}"/> </c:forEach><!-- 迭代固定次数 --> <c:forEach var="i" begin="1" end="10" step="3"> <c:out value="${i}"/> </c:forEach><!-- 这种循环相当于for(int i=1; i<10; i++), 其中step是指迭代的步长,默认为1. -->struts2:
<s:iterator value="#users" status="stuts"> <s:if test="#stuts.odd == true"> <!-- 判断是否为奇数行 --> <s:property value="userName"/> </s:if> <s:else> <s:property value="passWord"/> </s:else> </s:iterator>3. URL相关标签 JSTL:
<!-- 绝对路径 --> <c:import url="http://127.0.0.1:8080/hello/hello.jsp"/><!-- 相对路径 --> <c:import url="hello.jsp"/><!-- Encode --> <a href=" <c:url value='hello.jsp'><c:param name='userName' value='cyanbomb' /></c:url>"> </a><!-- 传递参数到指定的URL --> <c:import url="hello.jsp" charEncoding="gb2312"> <c:param name="userName" value="cyanbomb"/></c:import><!-- URL重定向 --> <c:redirect url="${myurl}"/><!-- 构造URL --> <c:url value="myurl" var="hello.jsp" scope="session"> <c:param name="userName" value="cyanbomb"/></c:url>Struts2:
<a href='<s:url value="/hello.jsp" />'>Hello</a><br/> <s:url id="url" value="/hello.jsp"> <s:param name="name">cyanbomb</s:param></s:url> <s:a href="%{url}">Hello</s:a>解除的疑问,list遍历问题
像这样一个list,里面有3条记录,每条记录包含两个对象,我把结果集(lstRooms)request到了页面,想遍历显示RrmRooms里的id,和RrmRoomType里的name.
我用JSTL实现如下:
<table> <c:forEach var="rm" items="${lstRooms}"> <tr> <td>${rm[0].id}</td> <td>${rm[1].name}</td> <tr> </c:forEach></table>STRUTS2实现如下:
<table> <s:iterator value="#lstRooms" status="stat"> <tr> <td> <s:property value="#lstRooms[#stat.index][0].id"/> </td> <td> <s:property value="#lstRooms[#stat.index][1].name"/> </td> <tr> </s:iterator> </table>
相关文章推荐
- 表格标签table深入了解
- WEB标准网页布局中尽量不要使用的HTML标签
- web标准知识――用途相似的标签
- h1标签的使用技巧
- HTML代码中标签的全部属性 中文注释说明
- jquery 实现两Select 标签项互调示例代码
- jQuery获取标签文本内容和html内容的方法
- JavaScript获取并更改input标签name属性的方法
- css样式标签和js语法属性区别
- 关于用Jquery的height()、width()计算动态插入的IMG标签的宽高的问题
- jQuery如何获取同一个类标签的所有值(默认无法获取)
- 解决JSTL foEach标签 刷新报错的方法
- js改变embed标签src值的方法
- ThinkPHP模板判断输出Empty标签用法详解
- php实现html标签闭合检测与修复方法
- ThinkPHP模板范围判断输出In标签与Range标签用法详解
- ThinkPHP分组下自定义标签库实例
- 彻底删除thinkphp3.1案例blog标签的方法
- thinkphp特殊标签用法概述
- JavaScript中的标签语句用法分析