JSTL(c标签)与Struts2(s标签)标签的常用功能对比
来源:互联网 发布:可以截取音乐的软件 编辑:程序博客网 时间:2024/06/14 03:12
1. 条件标签 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>
0 0
- JSTL(c标签)与Struts2(s标签)标签的常用功能对比
- JSTL(c标签)与Struts2(s标签)标签的常用功能对比
- JSTL(c标签)与Struts2(s标签)标签的常用功能对比
- JSTL(c标签)与Struts2(s标签)标签的常用功能对比
- JSTL(c标签)与Struts2(s标签)标签的常用功能对比
- JSTL(c标签)与Struts2(s标签)标签的常用功能对比
- JSTL c标签和Struts2 s标签常用功能对比
- JSTL(c标签)与Struts2(s标签)标签
- JSTL(c标签)与Struts2(s标签)标签
- Struts2标签的<s:set>标签与JSTL的<c:set>标签
- JSTL与Struts2标签的使用对比
- JSTL与Struts2标签的使用对比
- C标签(JSTL标签)
- JSTL与Struts2标签的使用对比 (转)
- JSTL与Struts2标签的使用对比==>
- jstl c:url 标签(类似 struts标签的 s:url)
- JSP标签JSTL(5)--常用的标签函数
- Struts 与 JSTL 标签对比
- Java千百问_05面向对象(011)_引用传递和值传递有什么区别
- acm_1003_pie
- Laxcus大数据管理系统2.0(14)- 后记
- [C++]类型转换
- Android:使用Gson解析复杂的JSON数据
- JSTL(c标签)与Struts2(s标签)标签的常用功能对比
- 大数据流式处理的利与弊
- python中urllib2高级应用 使用代理 模拟浏览器 cookie
- 升级Xcode7.3出现Cannot create __weak reference in file using manual reference counting 解决方法:
- UI控件之UIControl
- 浅谈特定型人工智能设计
- 代码单元和代码点
- Ruby元编程-学习笔记(三)-代码块
- ZOJ - 1295 Reverse Text