博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JSTL(c标签)与Struts2(s标签)标签的常用功能对比
阅读量:6463 次
发布时间:2019-06-23

本文共 2495 字,大约阅读时间需要 8 分钟。

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
>

转载地址:http://vgqzo.baihongyu.com/

你可能感兴趣的文章
java 字符串不为空_Java中判断String不为空的问题
查看>>
java中的http协议_java中Http协议的使用
查看>>
java 合成模式_《JAVA与模式》之合成模式
查看>>
java snippet_snippet,让你编码效率翻倍
查看>>
java cookie 覆盖_Java 会话技术 之cookie
查看>>
java 概率分布_将概率分布拟合到数据并找到它的累积分布函数
查看>>
java this()函数_java中this关键字怎么使用?
查看>>
java split limit_java split(String regex, int limit) 的使用
查看>>
java校园导航_校园导航的设计与实现(SSH,MySQL)(含录像)
查看>>
archlinux java环境_Arch Linux快速配置Java环境变量
查看>>
jfreechart java_java jfreechart
查看>>
python键盘输入转换为列表_Python键盘输入转换为列表的实例
查看>>
java字符是否数字_Java如何检查字符是否代表数字?
查看>>
java常用到的知识总结_java开发常用知识总结
查看>>
jsp中java向js传值_jsp想js,action传值
查看>>
opatch无法定位java_Java (1.6) could not be located. OPatch cannot proceed! — oracle-tech
查看>>
魏永红java课后答案_基于J2ME技术的手机信息查询系统的设计与实现
查看>>
java有交互式_Java 9 尝鲜之交互式编程环境
查看>>
galera mysql docker话_bug排查之空想导致的祸之MariaDB Galera Cluster的docker镜像构建中的遇到的坑爹事...
查看>>
php i=i 怎么实现,ThinkPHP的I方法使用详解
查看>>