如题所示,在做一个基于SSH框架的实战小项目时,发现不少地方都还在使用logic标签。这个标签不仅我不熟悉,而且在现在看来也显得过时了,因此我就想替换成我熟悉的JSTL标签
比如说,原来是这样的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<
logic:present
scope
=
"request"
name
=
"onSaleGoodsList"
>
<
table
border
=
"0"
>
<
s:iterator
id
=
"goods"
value
=
"#request.onSaleGoodsList"
>
<
tr
><
td
>
<!-- 显示在拍商品信息 -->
<
div
class
=
"goods_pic"
><
img
src
=
"/zxpm/${goods.goodsPic}"
title
=
"${goods.goodsDesc}"
style
=
"width:100px;border:dashed 1px green;"
></
img
></
div
></
td
>
<
td
valign
=
"top"
><
div
class
=
"goods_info"
style
=
"border:solid 0px blue;"
>
<
span
class
=
"info_title"
>商品名称</
span
> <
strong
>${goods.goodsName}</
strong
><
br
/>
<
span
class
=
"info_title"
>卖 家</
span
> <
em
>${goods.saler.userName}</
em
> <
br
/>
<
span
class
=
"info_title"
>起 拍 价</
span
> <
span
style
=
"color:green;"
>${goods.goodsPrice}</
span
><
br
/>
<!-- 如果用户已经登录,且不是该商品的卖家,则在该商品旁显示“出价”按钮 -->
<
logic:notEmpty
name
=
"user"
scope
=
"session"
>
<
logic:notEqual
name
=
"goods"
property
=
"saler.userId"
value
=
"${sessionScope.user.userId}"
>
<
a
class
=
"a_button"
href
=
"/zxpm/goods/doBid?goods.goodsId=${goods.goodsId}"
><
font
color
=
"red"
>我要出价</
font
></
a
>
</
logic:notEqual
>
</
logic:notEmpty
>
|
可以发现,这里面主要有一个logic:present,logic:notEmpty,logic:notEqual。虽然没用过,但是根据字面意思还是可以猜出是干什么的,因此就好替换了
(1)删掉跟logic:present相关的内容,因为不需要
(2)引入JSTL标签库:<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %>
(3)logic:notEmpty和logic:notEqual都替换成一个c:if标签
需要注意的是,c:if中的“空”不能用xxx == null这种形式来表示,而是empty xxx ;其次,如果c:if里有多个判断语句需要用 and 来连接,而不是 || 的形式
因此,上面那一段替换之后的效果是这样的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<
s:iterator
var
=
"goods"
value
=
"#request.onSaleGoodsList"
>
<
tr
>
<
td
>
<!-- 显示在拍商品信息 -->
<
div
class
=
"goods_pic"
>
<
img
src
=
"/OnlineAuction/uploadImages/${goods.goodsPic}"
title
=
"${goods.goodsDesc}"
style
=
"width: 100px; border: dashed 1px green;"
></
img
>
</
div
>
</
td
>
<
td
valign
=
"top"
><
div
class
=
"goods_info"
style
=
"border: solid 0px blue;"
>
<
span
class
=
"info_title"
>商品名称</
span
> <
strong
>${goods.goodsName}</
strong
><
br
/>
<
span
class
=
"info_title"
>卖 家</
span
> <
em
>${goods.saler.userName}</
em
>
<
br
/> <
span
class
=
"info_title"
>起 拍 价</
span
> <
span
style
=
"color: green;"
>${goods.goodsPrice}</
span
><
br
/>
<!-- 如果用户已经登录,且不是该商品的卖家,则在该商品旁显示“出价”按钮 -->
<
c:if
test
=
"${!empty sessionScope.user and goods.saler.userId != sessionScope.user.userId }"
>
<
a
class
=
"a_button"
href
=
"/OnlineAuction/goods/doBid.action?goods.goodsId=${goods.goodsId}"
><
font
color
=
"red"
>我要出价</
font
></
a
>
</
c:if
>
|
我碰到的情况主要就是这些了,根据意思相应的替换就行,难度不大
本文转自 pangfc 51CTO博客,原文链接:http://blog.51cto.com/983836259/1741694,如需转载请自行联系原作者