• <label id="pxtpz"><meter id="pxtpz"></meter></label>
      1. <span id="pxtpz"><optgroup id="pxtpz"></optgroup></span>

        當前位置:雨林木風下載站 > 技術(shù)開發(fā)教程 > 詳細頁面

        struts的一個容易的包含select下拉框的例子

        struts的一個容易的包含select下拉框的例子

        更新時間:2021-09-25 文章作者:未知 信息來源:網(wǎng)絡 閱讀次數(shù):

        首先,當然是需要你先對struts有一定的了解:)

        1. 定義相應頁面(client.jsp)的form bean,這里假設為ClientForm;注意在struts_config.xml中定義映射關(guān)系;client.jsp中包含了你需要的html form內(nèi)容,比如一個select下拉框;

        這里是form bean的代碼(其實就是一個java bean,繼承了ActionForm,然后需要重載reset和validate方法):
        -----------------------------------------------
        package com.egi.core.ioblock.form;

        import javax.servlet.http.HttpServletRequest;
        import org.apache.struts.action.ActionForm;
        import org.apache.struts.action.ActionMapping;
        import org.apache.struts.action.ActionError;
        import org.apache.struts.action.ActionErrors;

        /**
        *Copyright: Copyright (c) 2002</p> <p>
        *@author sjoy
        *@created2003年6月4日
        *@version1.0
        */

        public class LoginForm extends ActionForm {

        //-----------------------------Instance Variable
        private String appName = null;
        private String type = null;

        public String getAppName() {
        return appName;
        }

        public void setAppName(String appName) {
        this.appName = appName;
        }

        public String getType() {
        return type;
        }

        public void setType(String type) {
        this.type = type;
        }

        public void reset(ActionMapping mapping, HttpServletRequest request) {
        appName = null;
        type = null;
        }

        public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();
        if (appName == null || appName.length() < 1) {
        errors.add("application name", new ActionError("error.appname.required"));
        }
        return errors;
        }
        }
        -----------------------------------------------


        這里是ActionServlet代碼,繼承Action:
        -----------------------------------------------
        package com.egi.core.ioblock.action;

        import java.io.IOException;
        import java.sql.SQLException;
        import javax.servlet.ServletException;
        import javax.servlet.http.HttpSession;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;
        import org.apache.struts.action.Action;
        import org.apache.struts.action.ActionError;
        import org.apache.struts.action.ActionErrors;
        import org.apache.struts.action.ActionForm;
        import org.apache.struts.action.ActionMapping;
        import org.apache.struts.action.ActionForward;
        import com.egi.core.ioblock.form.LoginForm;
        import com.mainet.core.spreadsheet.db.MenusTreeTable;
        import com.mainet.core.spreadsheet.ProjectFactory;

        /**
        *Copyright: Copyright (c) 2002</p> <p>
        *@author sjoy
        *@created2003年6月4日
        *@version1.0
        */

        public class LoginAction extends Action {

        public ActionForward perform(ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response)
         throws IOException, ServletException {

        ActionErrors errors = new ActionErrors();
        String appName = ((LoginForm) form).getAppName();

        //下面是你所需要的一些邏輯
        ...
        HttpSession session = request.getSession();
        ...

        return mapping.findForward("success");
        }
        }

        -----------------------------------------------


        2. 寫一個bean,專門用來保存select的option集合。代碼如下:
        -----------------------------------------------
        package com.egi.core.ioblock.util;

        import java.io.Serializable;

        /**
        *Description: This class is a bean, used to represent one option in an HTML
        *drop-down 'select' list. It contains two properties - see {@link
        *getDisplayName()} and {@link getInternalId()} for a description. Useful in a
        *struts Form class for constructing a select list to pass to the jsp with the
        *<tt><html:select></tt> and <tt><html:option></tt> tags.</p> <p>
        *@author sjoy
        *@created2003年6月4日
        *@version1.0
        */

        public class HtmlSelectOption implements Serializable {
        private String id;
        private String displayName;

        /**
         *Constructor for the HtmlSelectOption object
         */
        public HtmlSelectOption() { }

        /**
         *Constructor for the HtmlSelectOption object
         *
         *@paramid Description of the Parameter
         *@paramdisplayNameDescription of the Parameter
         */
        public HtmlSelectOption(String id, String displayName) {
        this.id = id;
        this.displayName = displayName;
        }

        public String getDisplayName() {
        return displayName;
        }

        public void setDisplayName(String displayName) {
        this.displayName = displayName;
        }

        public String getId() {
        return id;
        }

        public void setId(String id) {
        this.id = id;
        }
        }
        -----------------------------------------------

        3. ok,接下來從db或者其它地方去取下拉列表中的具體內(nèi)容;
        java.util.Iterator iter = ....;//這里假設從數(shù)據(jù)庫中取得數(shù)據(jù)
        java.util.ArrayList list = new java.util.ArrayList();
        String obj;
        while(iter.hasNext()){
        obj = (String)iter.next();
        list.add(new com.egi.core.ioblock.util.HtmlSelectOption(obj,obj));
        }
        pageContext.setAttribute("appNames", list);

        注意:這段邏輯也可以寫在ClienetForm中通過javabean的方式在頁面上獲得這個集合。

        4. 然后就是頁面上使用啦:)
        <html:select property="type">
        <html:options collection="appNames" property="id"
         labelProperty="displayName"/>
        </html:select>

        搞定!

        溫馨提示:喜歡本站的話,請收藏一下本站!

        本類教程下載

        系統(tǒng)下載排行

        主站蜘蛛池模板: 爱情岛亚洲论坛在线观看| 亚洲成人在线电影| 亚洲欧美成人综合久久久| 亚洲视频在线免费播放| 4444亚洲国产成人精品| 中文字幕天天躁日日躁狠狠躁免费| 亚洲午夜未满十八勿入| 成人免费区一区二区三区| 久久综合图区亚洲综合图区| 日韩在线天堂免费观看| 亚洲精品久久无码av片俺去也| 日韩黄色免费观看| 四虎精品成人免费视频| 亚洲 综合 国产 欧洲 丝袜| 国产黄在线播放免费观看| 亚洲精品无码鲁网中文电影| 免费国产黄网站在线观看视频| 亚洲熟妇av一区二区三区下载| 99热在线精品免费全部my| 亚洲精品乱码久久久久蜜桃| 亚洲精品国产V片在线观看| 在线毛片片免费观看| 亚洲第一成年人网站| 国产乱码免费卡1卡二卡3卡| 亚洲av色香蕉一区二区三区蜜桃| www.亚洲色图.com| 日韩精品免费视频| 亚洲乱码一二三四区乱码| 免费在线观看视频a| 免费精品99久久国产综合精品| 亚洲喷奶水中文字幕电影| 国产精品国产午夜免费福利看| 三年片免费观看大全国语| 亚洲成电影在线观看青青| 国产在线不卡免费播放| 18禁超污无遮挡无码免费网站 | 国产成人免费高清激情明星| 亚洲熟妇无码AV| 久久久久久久亚洲精品| 91嫩草免费国产永久入口| 男女猛烈激情xx00免费视频|