溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

NetBeans Struts應(yīng)用的示例分析

發(fā)布時間:2021-12-27 09:22:32 來源:億速云 閱讀:149 作者:小新 欄目:編程語言

這篇文章主要為大家展示了“NetBeans Struts應(yīng)用的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“NetBeans Struts應(yīng)用的示例分析”這篇文章吧。

由于公司的一個系統(tǒng)需要進行WEB化,對幾種常見的WEB技術(shù)進行了調(diào)查。試用了下NetBeans Struts,理解了NetBeans Struts的開發(fā)流程。以下是試作的一個Login的小例子。

開發(fā)環(huán)境:JDK1.5.06 Struts1.2.7 NetBeans5.0(內(nèi)嵌Tomcat5.5.9)

1 首先,使用NB創(chuàng)建一個WEB工程:Hello。選中是否使用Struts1.2.7的復(fù)選框。

2 創(chuàng)建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 創(chuàng)建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 創(chuàng)建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"> &nbsp;&nbsp;  <input type="reset" value="Reset"> </td> </tr> </table> </form> </center> </body> </html>

5 修改struts-config.xml文件,添加以下的內(nèi)容:

<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服務(wù),即可。

7 測試:

啟動Tomcat,在瀏覽器中輸入http://localhost:8084/Helo/login.jsp即可。

以上是“NetBeans Struts應(yīng)用的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI