熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

struts標簽使用舉例--logic篇

2022-06-13   來源: Java開源技術 
  logic:empty

  該標簽是用來判斷是否為空的如果為空該標簽體中嵌入的內容就會被處理該標簽用於以下情況

  )當Java對象為null時

  )當String對象為

  )當javautilCollection對象中的isEmpty()返回true時

  )當javautilMap對象中的isEmpty()返回true時
          eg 
            <logic:empty   name=userList>   
                 
           </logic:empty> 
           該句等同於
           if   (userListisEmpty())   {   
                    
           }   
  logic:notEmpty
          該標簽的應用正好和logic:empty標簽相反
logic:equal
          該標簽為等於比較符
          eg 比較用戶的狀態屬性是否若為輸出啟用;
                 <logic:equal   name=user   property=state   value=>
                     啟用
                 </logic:equal>
         eg 如果上例中的value值是動態獲得的例如需要通過bean:write輸出因struts不支持標簽嵌套可采用EL來解決該問題
                <logic:equal   name=charge   property=num   value=${businessnum}>   
                   
                </logic:equal>
  logic:notEqual
          該標簽意義與logic:equal相反使用方法類似
logic:forward
          該標簽用於實現頁面導向查找配置文件的全局forward
          eg <logic:forward name=index/>
logic:greaterEqual
          為大於等於比較符
          eg 當某學生的成績大於等於輸出優秀
               <logic:greaterEqual name=student property=score value=>
                  優秀
            </logic:greaterEqual>
logic:greaterThan
          此為大於比較符使用方法同logic:greaterEqual略;
logic:lessEqual
          此為小於等於比較符使用方法同logic:greaterEqual略;
logic:lessThan
          此為小於比較符使用方法同logic:greaterEqual略;
logic:match
          此標簽比較對象是否相等
          eg 檢查在request范圍內的name屬性是否包含amigo 
            <logic:match name=name scope=request value=amigo>
                  <bean:write name=name/>中有一個amigo
            </logic:match>
         eg 檢查在request范圍內的name屬性是否已amigo作為起始字符串
           <logic:match name=name scope=request value=amigo location=start>
               <bean:write name=name/>以amigo作為起始字符串
            </logic:match>
         eg 
            <logic:match header=useragent value=Windows>
               你運行的是Windows系統
            </logic:match>
 logic:notMatch

  此標簽用於比較對象是否不相同與logic:match意義相反使用方法類似
     logic:messagePresent
          該標簽用於判斷ActionMessages/ActionErrors對象是否存在
          eg 如果存在error信息將其全部輸出
               <logic:messagePresent property=error
                  <html:messages property=error id=errMsg
                        <bean:write name=errMsg/> 
                  </html:messages>   
               </logic:messagePresent >
      logic:messagesNotPresent
          該標簽用於判斷ActionMessages/ActionErrors對象是否不存在使用方法與logic:messagePresent類似
logic:present
           此標簽用於判斷request對象傳遞參數是否存在
           eg user對象和它的name屬性在request中都存在時輸出相應字符串
              <logic:present name=user property=name>
                  user對象和該對象的name屬性都存在
            </logic:present> 
          eg 若有一個名字為user的JavaBean輸出對應字符串
             <logic:present name=user >
                  有一個名字為user的JavaBean
            </logic:present>
          eg 
            <logic:present header=useragent>
                  we got a useragent header
            </logic:present>
   logic:notPresent
           此標簽用於判斷request對象傳遞參數是否不存在意義與了logic:present相反使用方法類似
   logic:redirect
           該標簽用於實現頁面轉向可傳遞參數
           eg <logic:redirect />
       
logic:iterator
            用於顯示列表為collection的值(List ArrayListHashMap等)
            eg 逐一輸出用戶列表(userlList)中用戶的姓名
               <logic:iterate  id=user name=userList>
                  <bean:write name=user property=name/><br>
               </logic:iterate>
            eg 從用戶列表中輸出從開始的兩個用戶的姓名
               <logic:iterate  id=user name=userList indexId=index  offset= length=>
                  <bean:write name=index/><bean:write name=user property=name/><br>
               </logic:iterate>
            eg 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= offset=>
                           <bean:write name=address/><br>
                       </logic:iterate>
               </logic:iterate>


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28392.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.