使用JSTL标签库替换Struts1中的logic标签

    如题所示,在做一个基于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 >&nbsp;< strong >${goods.goodsName}</ strong >< br  />
             < span  class = "info_title" >卖  &nbsp;&nbsp;   家</ span >&nbsp;< em >${goods.saler.userName}</ em > < br  />
             < span  class = "info_title" >起 拍 价</ span >&nbsp;< 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:presentlogic:notEmptylogic: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 >&nbsp;< strong >${goods.goodsName}</ strong >< br  />
                         < span  class = "info_title" >卖 &nbsp;&nbsp; 家</ span >&nbsp;< em >${goods.saler.userName}</ em >
                         < br  /> < span  class = "info_title" >起 拍 价</ span >&nbsp;< 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,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值