使用MyEclipse6開發Struts+Spring應用程式(2)

來源:互聯網
上載者:User
 

2、開發Struts應用程式(1) 建立Web Project l        指定工程名字:Samples(2) 添加Struts開發功能l        右擊Samples工程,MyEclipse -> Add Struts Capabilities: l        選擇Struts1.3l        指定base package:org.xqtu.samplpes(3) 建立JSP頁面l        開啟struts-config.xmll        Design模式下,面板中單擊Add JSP page,在布局中點擊: l        指定JSP檔案路徑:/Samples/WebRoot/WEB-INF/jspl        指定JSP檔案名稱字:success.jspl        選擇Struts1.2/1.3的模版(4) 建立Form、Action和JSPl        布局中右擊,New -> Form, Action and JSP: l        指定Use Case:Loginl        為了應用程式分層清晰,修改Form的package:org.xqtu.Samples.web.form.LoginForml        通過Add按鈕添加ActionForm的屬性l        選擇JSP Tab: l        選擇 Create JSP forml        指定JSP Path:/WEB-INF/jsp/login.jspl        點擊Next按鈕,建立Action: l        同樣,修改Action的package:org.xqtu.Samples.web.action.LoginActionl        選擇Forwards Tabl        通過Add按鈕指定ActionForwardl        點擊Finish按鈕,自動產生Action和ActionForm類(5) Action類編碼l        在沒有使用DB訪問之前,使用簡單的邏輯判斷:    public ActionForward execute(ActionMapping mapping, ActionForm form,            HttpServletRequest request, HttpServletResponse response) {        LoginForm loginForm = (LoginForm) form;         if ("123456".equals(loginForm.getPassword())) {            request.setAttribute("userid", loginForm.getUserid());            return mapping.findForward("success");        }         request.setAttribute("loginError",                "login failure, userid or password incorrect!");        return mapping.findForward("failure");    }(6) 修改login.jsp        <html:form action="/login">            userid : <html:text property="userid" />            <br />            password : <html:password property="password" />            <br />            <html:submit />            <logic:notEmpty name="loginError" scope="request">                <bean:write name="loginError" scope="request" />            </logic:notEmpty>        </html:form>(7) 修改success.jsp<body>    Hello    <bean:write name="userid" scope="request" />    , you successfully logged in!</body>(8) 修改index.jspl        為了防止JSP檔案被直接存取,JSP檔案通常放在WebRoot的/WEB-INF下,通過WebRoot下的index.jsp檔案forward到JSP檔案l        開啟struts-config.xmll        Design模式下,面板中單擊Add Global Forward,在布局中點擊: l        指定Forward的名字:loginl        指定Forward的路徑:/WEB-INF/jsp/login.jspl        修改index.jsp: <body>        <logic:forward name="login"/> </body> 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.