Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > 在NetBeans IDE下开发Struts应用
【标  题】:在NetBeans IDE下开发Struts应用
【关键字】:NetBeans,IDE,Struts
【来  源】:http://www.cublog.cn/u/8862/showart.php?id=109622

在NetBeans IDE下开发Struts应用

Your Ad Here

由于公司的一个系需要WEB化,WEB术进行了调查用了下Struts,理解了Struts开发流程。以下是作的一个Login的小例子。

 

开发环境:JDK1.5.06 Struts1.2.7 NetBeans5.0(内嵌Tomcat5.5.9)

 

1 首先,使用NB建一个WEB工程:Helo中是否使用Struts1.2.7复选框。

 

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>

            <h1>Welcome login into the system</h1>

            <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文件,添加以下的内容:

<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>

5 部署:

  使用NetBeans部署这个Web服务,即可。

 

6 测试:

  启动Tomcat,在浏览器中输入http://localhost:8084/Helo/login.jsp即可。

 

java经典面试题集(转):【上一篇】
Perl——《PleacPerl》.chm:【下一篇】
【相关文章】
  • 17.5.4 Override methods
  • 17.6.3 Virtual, sealed, override, and abstrac
  • LIST of MPEG-4 AVC/H.264 VIDEO CODECS
  • Struts1.2中配置数据源
  • VS 2005 TFS MSSCCI Provider
  • Perl——Modperl_guide_cn.pdf
  • Red Hat Enterprise Linux 3: Security Guide
  • 移动jdk后,导致NetBeans5.0无法启动的修复
  • mysql5.0 Certification Study Guide DBA (1)
  • Guide to Cisco Frame Relay Traffic Shaping
  • 【随机文章】
  • 在网页中实现细线边框的两种方法
  • 关于HACMP的启动和关闭脚本!!
  • Windows 2000 用户权限
  • RawSocke原始套接字实现Sniffer嗅探 下
  • 新课题:社区以太网布线
  • 《C和指针》读书笔记(1)
  • MYSQL到ORACLE程序迁移的注意事项
  • 《超越C++标准库:Boost库导引》:Boost库简介—输入/输出
  • A piecture of J2EE Core Patterns
  • 天堂2 50级以后的先知跟谁组队冲等最快(二人小组)
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.