<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-10  評論-22  文章-1  trackbacks-0

    常用的Struts標簽庫有以下五大類:

    1.HTML Tag:

    用來創(chuàng)建能夠和Struts框架以及其它相應(yīng)的HTML標簽交互的HTML輸入表單;

    如:<html:form></html:form>,<html:text/>,<html:password/>,<html:radio/>,<html:checkbox/>,<htmlmultibox>

    2.Bean Tag

    該標簽庫包含的標簽可以用來創(chuàng)建bean、訪問bean和訪問bean的屬性。

     如:<bean:write/>:用于將bean的屬性輸送到j(luò)sp頁面,<bean:define/>定義一個新的bean

    3.Logic Tag

    該標簽庫包含的標簽可以用來進行邏輯判斷、集合迭代和流程控制。

    如:<logic:iterate/>:用來循環(huán)迭代,<logic:eaual/>:用來進行邏輯判斷

    4.Nested:增強對其他Struts標簽的嵌套使用能力

    該標簽庫建立在前三個標簽庫的基礎(chǔ)上,具有前三個標簽庫的所有功能,只是允許標簽間的嵌套。

    5.Template Tag

    隨著Titles框架包的出現(xiàn),此標記已開始減少使用

    下面介紹幾個最常用的標簽:

    <html:check box/>一般用于一個選項的復(fù)選框

    <html:multibox/>一般用于多個選項的復(fù)選框

    <bean:write name="user" property="username"/>等同于EL表達示:${user.username}

    <bean:define id="inter" name="user" property="interest" type="java.lang.String"/>定義一個bean

    <bean:message key=" " arg0=" "/> key 定義在資源文件中,args0[1,2]為參數(shù)

    <logic:iterate name="list" id="user"> 等同于JSTL的:<c:foeach item=${list} var="user"/>

    <logic:equal name="user" property="sex" value="0"/>等同于JSTL的:<c:when test=""/>

    <logic:empty />標簽是用來判斷是否為空的。如果為空,該標簽體中嵌入的內(nèi)容就會被處理

    <logic:empty name="listForm" property = "persons">
    <div>集合persons為空!</div>
    </logic:empty>

    1.下面給一個表單的完整代碼:

    <body>
        
    <center>
            
    <html:form action="/user">
            用戶名:
    <html:text property="user.username"></html:text><p/>
            密碼:
    <html:text property="user.pwd"></html:text><p/>
            性別:
    <html:radio property="user.sex" value=""></html:radio>
                
    <html:radio property="user.sex" value=""></html:radio><p/>
            城市:
    <html:select property="user.city">
                
    <html:option value="">請選擇</html:option>
                
    <html:option value="武漢">武漢</html:option>
                
    <html:option value="上海">上海</html:option>
                
    <html:option value="北京">北京</html:option>
            
    </html:select><p/>
            愛好:
    <html:multibox property="interest" value="看書"/>看書
                
    <html:multibox property="interest" value="游戲"/>游戲
                
    <html:multibox property="interest" value="睡覺"/>睡覺<p/>
                
    <html:submit/><html:cancel/>
            
    </html:form>
        
    </center>
        
    </body>

    使用html標簽作為表單輸入,可以方便的使用驗證框架即:<html:errors property="username">

    2.下面給一個顯示數(shù)據(jù)的代碼:

    <table align="center" border="1" width="600">
            
    <caption>用戶注冊信息</caption>
            
    <tr>
                
    <td>用戶名</td>
                
    <td>密碼</td>
                
    <td>性別</td>
                
    <td>城市</td>
                
    <td>愛好</td>
                
    <td colspan="2" align="center">操作</td>
            
    </tr>
            
    <logic:iterate name="list" id="user">
            
    <tr>
                
    <td><bean:write name="user" property="username"/></td>
                
    <td><bean:write name="user" property="pwd"/></td>
                
    <td><bean:write name="user" property="sex"/></td>
                
    <td><bean:write name="user" property="city"/></td>
                
    <td>
                    
    <bean:define id="interest" name="user" property="interest" type="java.lang.String"></bean:define>
                    
    <logic:iterate id="inter" collection="<%=StringUtil.stringChange2(interest)%>">
                        $
    {inter}
                    
    </logic:iterate>
                
    </td>
                
    <td><a href="del.do?userid=${user.userid}">刪除</a></td>
                
    <td><a href="upd.do?userid=${user.userid}">修改</a></td>
            
    </tr>
            
    </logic:iterate>
        
    </table>

    作為顯示數(shù)據(jù),Struts標簽并不比Jstl與EL方便,因此,本人更習慣用后者

    其實Struts標簽的好處,并不是上面這些,而是它可利用ActionForm來填充數(shù)據(jù)

    比如我們在做頁面數(shù)據(jù)修改的時候,會讓當前頁面數(shù)據(jù)顯示到顯示修改頁面,這樣利于客戶端修改

    以前我們這樣做的:根據(jù)id從數(shù)據(jù)庫查出,然后使用html的value屬性填充,現(xiàn)在有了Struts標簽,就不需要那么麻煩了

    直接在Action里填充ActionForm的數(shù)據(jù)就搞定了

    public ActionForward upd(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) 
    {
            UserForm userForm 
    = (UserForm) form;
            
    int userid = Integer.parseInt(request.getParameter("userid"));
            UserInfo user 
    = biz.findUser(userid);
            String[]interest 
    = StringUtil.stringChange2(user.getInterest());
            
    //將用戶信息填充到ActionForm
            userForm.setUser(user);
            userForm.setInterest(interest);
            
    return mapping.findForward("upd");
        }
    然后在修改頁面顯示,請往下看:
    <html:form action="/doupd">
            用戶名:
    <html:text property="user.username"></html:text><p/>
            密碼:
    <html:text property="user.pwd"></html:text><p/>
            性別:
    <html:radio property="user.sex" value=""></html:radio>
                
    <html:radio property="user.sex" value=""></html:radio><p/>
            城市:
    <html:select property="user.city">
                
    <html:option value="">請選擇</html:option>
                
    <html:option value="武漢">武漢</html:option>
                
    <html:option value="上海">上海</html:option>
                
    <html:option value="北京">北京</html:option>
            
    </html:select><p/>
            愛好:
    <html:multibox property="interest" value="看書"/>看書
                
    <html:multibox property="interest" value="游戲"/>游戲
                
    <html:multibox property="interest" value="睡覺"/>睡覺<p/>
                
    <html:submit value="修改"/>
            
    </html:form>
    怎么樣,簡單方便吧,其實Struts標簽還是有它的好處的。
    posted on 2009-03-14 23:47 獨孤行 閱讀(1594) 評論(1)  編輯  收藏 所屬分類: Struts

    評論:
    # re: Struts核心標簽(原創(chuàng)) 2009-03-15 13:05 | 陽衡鋒
    好像界面層的標簽還是自己封裝比較好,我現(xiàn)在的項目的,我就封裝了幾個標簽。沒有花多少功夫,基本上只要封裝select radio checkbox 就可以了。其他的直接寫html+el反而比較好。  回復(fù)  更多評論
      

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 香蕉高清免费永久在线视频 | 四虎在线最新永久免费| 国产亚洲?V无码?V男人的天堂| 成全视频免费高清| 亚洲人成影院午夜网站| 最近在线2018视频免费观看| 亚洲av无码一区二区乱子伦as | 亚洲男人天堂2022| 国产va免费精品| 国产成人99久久亚洲综合精品| 国产亚洲蜜芽精品久久| 免费观看国产小粉嫩喷水| 日韩电影免费在线观看网址 | 国产乱子伦精品免费无码专区| 亚洲AV成人精品一区二区三区| 国产国产成年年人免费看片| 精品亚洲麻豆1区2区3区| 国产精品免费无遮挡无码永久视频 | 99久久99久久精品免费看蜜桃| 337p日本欧洲亚洲大胆裸体艺术| 一本大道一卡二大卡三卡免费| 久久久久久久尹人综合网亚洲| 日韩免费无码一区二区三区| 亚洲成a人片在线观看中文app| 男人的好看免费观看在线视频| 亚洲国产成人久久精品影视| **一级毛片免费完整视| 亚洲欧美日韩综合俺去了| 亚洲综合免费视频| 亚洲妇女无套内射精| 免费人成视频在线| 美女裸免费观看网站| 亚洲成AV人片天堂网无码| 精品福利一区二区三区免费视频 | 亚洲成人中文字幕| 成人免费午夜在线观看| 日本中文字幕免费看| 亚洲最新在线视频| 四虎精品亚洲一区二区三区| 亚洲国产午夜精品理论片在线播放| 亚洲国产91精品无码专区|