自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

NetBeans Struts應(yīng)用實(shí)例詳解

開發(fā) 后端
本文是NetBeans Struts應(yīng)用實(shí)例詳解,NetBeans IDE下如何進(jìn)行Struts開發(fā)是我們實(shí)際工作中會(huì)遇到的問題。本文將以實(shí)際例子為大家進(jìn)行講解。

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

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

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

2 創(chuàng)建LoginActionForm.java文件:

  1. public class LoginActionForm extends ActionForm ...{  
  2. private String userName;  
  3. private String userPwd;  
  4. public String getUserName() ...{  
  5. return userName;  
  6. }  
  7. public void setUserName(String userName) ...{  
  8. this.userName = userName;  
  9. }  
  10. public void setUserPwd(String userPwd) ...{  
  11. this.userPwd = userPwd;  
  12. }  
  13. public String getUserPwd() ...{  
  14. return userPwd;  
  15. }  
  16.  } 

3 創(chuàng)建LoginAction.java文件:

  1. public class LoginAction extends Action ...{  
  2. public ActionForward execute(ActionMapping mapping,  
  3. ActionForm form,  
  4. HttpServletRequest request,  
  5. HttpServletResponse response) ...{  
  6. LoginActionForm loginForm = (LoginActionForm) form;  
  7. String forword="success";  
  8. System.out.println("Name:" + loginForm.getUserName());  
  9. System.out.println("Passwd:" + loginForm.getUserPwd());  
  10. return mapping.findForward(forword);  
  11. }  
  12.  } 

4 創(chuàng)建Login.jsp文件:

  1. <%@page contentType="text/html; charset=GBK"%> 
  2. <html> 
  3. <head> 
  4. <title>login</title> 
  5. </head> 
  6. <body bgcolor="#ffffff"> 
  7. <center> 
  8. <h1>Welcome login into the system</h1> 
  9. <form name="loginForm" method="post" action="loginAction.do"> 
  10. <br> 
  11. <br> 
  12. <table align="center"> 
  13. <tr> 
  14. <td>UserName</td> 
  15. <td> 
  16. <input type="text" name="userName"/> 
  17. </td> 
  18. </tr> 
  19. <tr> 
  20. <td>Password</td> 
  21. <td> 
  22. <input type="password" name="userPwd"/> 
  23. </td> 
  24. </tr> 
  25. <tr> 
  26. <td> </td> 
  27. <td> 
  28. <input type="submit" name="Submit" value="Login"> 
  29. &nbsp;&nbsp;  
  30. <input type="reset" value="Reset"> 
  31. </td> 
  32. </tr> 
  33. </table> 
  34. </form> 
  35. </center> 
  36. </body> 
  37. </html> 

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

  1. <form-beans> 
  2. <form-bean name = "AddUserActionForm" type = "com.myapp.struts.AddUserActionForm"/> 
  3. <form-bean name="loginActionForm" type="com.myapp.struts.LoginActionForm" /> 
  4. </form-beans> 
  5. <global-forwards> 
  6. <forward name="welcome" path="/Welcome.do"/> 
  7. <forward name="login" path="/login.jsp" /> 
  8. </global-forwards> 
  9. <action-mappings> 
  10. <action path="/Welcome" forward="/welcomeStruts.jsp"/> 
  11. <action input="/login.jsp" name="loginActionForm" path="/loginAction" scope="request" type = "com.myapp.struts.LoginAction" validate="true" /> 
  12. </action-mappings> 

6 部署:

使用NetBeans部署這個(gè)Web服務(wù),即可。

7 測(cè)試:

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

【編輯推薦】

  1. 讓Eclipse和NetBeans共享同一個(gè)項(xiàng)目
  2. NetBeans 6.5 界面美化與字體設(shè)置
  3. Eclipse還是Netbeans
  4. 如何在NetBeans中連接MySQL數(shù)據(jù)庫(kù)
  5. 八大技術(shù)牛人點(diǎn)評(píng)NetBeans 6.5
責(zé)任編輯:彭凡 來(lái)源: tech.ddvip.com
相關(guān)推薦

2009-06-15 15:16:00

netbeans sw平臺(tái)開發(fā)

2009-06-09 10:24:35

NetBeansStruts頁(yè)面布局

2011-05-24 10:30:31

PythonNetBeans ID

2010-06-22 10:28:04

linux at命令

2011-09-08 13:11:07

Android Wid實(shí)例

2010-06-18 10:33:03

Linux Acces

2012-02-14 15:51:13

JavaHibernate

2009-07-06 17:07:11

JSP實(shí)例

2010-06-24 16:55:47

Linux chgrp

2009-09-11 12:31:52

C#實(shí)例詳解TypeConvert

2009-08-28 12:47:30

C#靜態(tài)方法應(yīng)用

2009-09-04 18:09:12

C# Main函數(shù)

2009-09-02 19:12:37

C#遞歸

2009-06-08 16:52:00

2009-09-01 15:47:20

C#取整函數(shù)

2009-09-02 11:18:10

C#動(dòng)態(tài)數(shù)組

2009-06-04 10:31:00

struts.jar詳解

2009-07-20 16:51:59

Struts2.0+i

2009-06-18 15:56:49

Struts和Spri

2009-03-24 10:30:35

SpringStruts集成
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)