posts - 297,  comments - 1618,  trackbacks - 0
  1. logic:empty

          该标签是用来判断是否为空的。如果为空,该标签体中嵌入的内容就会被处理。该标签用于以下情况:

         1)当Java对象为null时;

         2)当String对象为""时;

         3)当java.util.Collection对象中的isEmpty()返回true时;

         4)当java.util.Map对象中的isEmpty()返回true时。
          eg. 
            <logic:empty   name="userList">   
              ...   
           </logic:empty> 
           该句等同于:
           if   (userList.isEmpty())   {   
                 ...   
           }   
   2.  logic:notEmpty
          该标签的应用正好和logic:empty标签相反,略。
   3. logic:equal
          该标签为等于比较符。
          eg1. 比较用户的状态属性是否1,若为1,输出"启用";
                 <logic:equal   name="user"   property="state"   value="1">
                     启用
                 </logic:equal>
         eg2. 如果上例中的value值是动态获得的,例如需要通过bean:write输出,因struts不支持标签嵌套,可采用EL来解决该问题。
                <logic:equal   name="charge"   property="num"   value="${business.num}">   
                    ......
                </logic:equal>
    4. logic:notEqual
          该标签意义与logic:equal相反,使用方法类似,略。
    5. logic:forward
          该标签用于实现页面导向,查找配置文件的全局forward。
          eg. <logic:forward name="index"/>
    6. logic:greaterEqual
          为大于等于比较符。
          eg. 当某学生的成绩大于等于90时,输出“优秀”:
               <logic:greaterEqual name="student" property="score" value="90">
                  优秀
            </logic:greaterEqual>
    7. logic:greaterThan
          此为大于比较符,使用方法同logic:greaterEqual,略;
    8. logic:lessEqual
          此为小于等于比较符,使用方法同logic:greaterEqual,略;
    9. logic:lessThan
          此为小于比较符,使用方法同logic:greaterEqual,略;
    10. logic:match
          此标签比较对象是否相等;
          eg1. 检查在request范围内的name属性是否包含"amigo"串: 
            <logic:match name="name" scope="request" value="amigo">
                  <bean:write name="name"/>中有一个“amigo”串。
            </logic:match>
         eg2. 检查在request范围内的name属性是否已“amigo”作为起始字符串:
           <logic:match name="name" scope="request" value="amigo" location="start">
               <bean:write name="name"/>以“amigo”作为起始字符串。
            </logic:match>
         eg3. 
            <logic:match header="user-agent" value="Windows">
               你运行的是Windows系统
            </logic:match>
    11.  logic:notMatch

          此标签用于比较对象是否不相同,与logic:match意义相反,使用方法类似,略。
     12. logic:messagePresent
          该标签用于判断ActionMessages/ActionErrors对象是否存在;
          eg. 如果存在error信息,将其全部输出:
               <logic:messagePresent property="error"> 
                  <html:messages property="error" id="errMsg" > 
                        <bean:write name="errMsg"/> 
                  </html:messages>   
               </logic:messagePresent >
     13. logic:messagesNotPresent
          该标签用于判断ActionMessages/ActionErrors对象是否不存在,使用方法与logic:messagePresent类似,略
      14. logic:present
           此标签用于判断request对象传递参数是否存在。
           eg1. user对象和它的name属性在request中都存在时,输出相应字符串:
              <logic:present name="user" property="name">
                  user对象和该对象的name属性都存在
            </logic:present> 
          eg2. 若有一个名字为“user”的JavaBean,输出对应字符串:
             <logic:present name="user" >
                  有一个名字为“user”的JavaBean。
            </logic:present>
          eg3. 
            <logic:present header="user-agent">
                  we got a user-agent header.
            </logic:present>
      15. logic:notPresent
           此标签用于判断request对象传递参数是否不存在,意义与了logic:present相反,使用方法类似,略。
      16. logic:redirect
           该标签用于实现页面转向,可传递参数。
           eg1. <logic:redirect href="http://hao123.com"/>
       
       17. logic:iterator
            用于显示列表为collection的值(List ,ArrayList,HashMap等)。
            eg1. 逐一输出用户列表(userlList)中用户的姓名:
               <logic:iterate  id="user" name="userList">
                  <bean:write name="user" property="name"/><br>
               </logic:iterate>
            eg2. 从用户列表中输出从1开始的两个用户的姓名
               <logic:iterate  id="user" name="userList" indexId="index"  offset="1" length="2">
                  <bean:write name="index"/>.<bean:write name="user" property="name"/><br>
               </logic:iterate>
            eg3. logic:iterator标签的嵌套举例
                <logic:iterate id="user" indexId="index" name="userList">
                       <bean:write name="index"/>. <bean:write name="user" property="name"/><br>
                       <logic:iterate id="address" name="user" property="addressList" length="3" offset="1">
                           <bean:write name="address"/><br>
                       </logic:iterate>
               </logic:iterate>

posted on 2007-02-20 18:02 阿蜜果 阅读(2615) 评论(2)  编辑  收藏 所属分类: Struts


FeedBack:
# re: struts标签使用举例--logic篇
2007-02-20 18:32 | 山风小子
收下了,多谢 :)  回复  更多评论
  
# re: struts标签使用举例--logic篇
2008-01-06 13:01 | 木偶人
谢了  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
<2007年2月>
28293031123
45678910
11121314151617
18192021222324
25262728123
45678910

      生活将我们磨圆,是为了让我们滚得更远——“圆”来如此。
      我的作品:
      玩转Axure RP  (2015年12月出版)
      

      Power Designer系统分析与建模实战  (2015年7月出版)
      
     Struts2+Hibernate3+Spring2   (2010年5月出版)
     

留言簿(262)

随笔分类

随笔档案

文章分类

相册

关注blog

积分与排名

  • 积分 - 2279403
  • 排名 - 3

最新评论

阅读排行榜

评论排行榜