這篇文章主要為大家展示了“NetBeans Struts應用的示例分析”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“NetBeans Struts應用的示例分析”這篇文章吧。
由于公司的一個系統需要進行WEB化,對幾種常見的WEB技術進行了調查。試用了下NetBeans Struts,理解了NetBeans Struts的開發流程。以下是試作的一個Login的小例子。
開發環境:JDK1.5.06 Struts1.2.7 NetBeans5.0(內嵌Tomcat5.5.9)
1 首先,使用NB創建一個WEB工程:Hello。選中是否使用Struts1.2.7的復選框。
2 創建LoginActionForm.java文件:
public class LoginActionForm extends ActionForm ...{ private String userName; private String userPwd; public String getUserName() ...{ return userName; } public void setUserName(String userName) ...{ this.userName = userName; } public void setUserPwd(String userPwd) ...{ this.userPwd = userPwd; } public String getUserPwd() ...{ return userPwd; } }3 創建LoginAction.java文件:
public class LoginAction extends Action ...{ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) ...{ LoginActionForm loginForm = (LoginActionForm) form; String forword="success"; System.out.println("Name:" + loginForm.getUserName()); System.out.println("Passwd:" + loginForm.getUserPwd()); return mapping.findForward(forword); } }4 創建Login.jsp文件:
<%@page contentType="text/html; charset=GBK"%> <html> <head> <title>login</title> </head> <body bgcolor="#ffffff"> <center> <h2>Welcome login into the system</h2> <form name="loginForm" method="post" action="loginAction.do"> <br> <br> <table align="center"> <tr> <td>UserName</td> <td> <input type="text" name="userName"/> </td> </tr> <tr> <td>Password</td> <td> <input type="password" name="userPwd"/> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="Submit" value="Login"> <input type="reset" value="Reset"> </td> </tr> </table> </form> </center> </body> </html>
5 修改struts-config.xml文件,添加以下的內容:
<form-beans> <form-bean name = "AddUserActionForm" type = "com.myapp.struts.AddUserActionForm"/> <form-bean name="loginActionForm" type="com.myapp.struts.LoginActionForm" /> </form-beans> <global-forwards> <forward name="welcome" path="/Welcome.do"/> <forward name="login" path="/login.jsp" /> </global-forwards> <action-mappings> <action path="/Welcome" forward="/welcomeStruts.jsp"/> <action input="/login.jsp" name="loginActionForm" path="/loginAction" scope="request" type = "com.myapp.struts.LoginAction" validate="true" /> </action-mappings>
6 部署:
使用NetBeans部署這個Web服務,即可。
7 測試:
啟動Tomcat,在瀏覽器中輸入http://localhost:8084/Helo/login.jsp即可。
以上是“NetBeans Struts應用的示例分析”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。