`
happy20070302
  • 浏览: 97654 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

标准Action与ActionForm编写

阅读更多


1  Action的编写:
 
     import javax.servlet.http.HttpServletRequest;
     import javax.servlet.http.HttpServletResponse;
     import org.apache.struts.action.Action;
     import org.apache.struts.action.ActionForm;
     import org.apache.struts.action.ActionForward;
     import org.apache.struts.action.ActionMapping;
     public class loginaction extends Action {
             @Override
     public ActionForward execute(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response)
       throws Exception {
       login_actionform lgf=(login_actionform)form;
         String name=lgf.getUsername();
         String pass=lgf.getPasswors();
           if("ss".equals(name))
              {return mapping.findForward("successed");}
           else
              {return mapping.findForward("error");}
  }
}
2 ActionForm的编写:
  import org.apache.struts.action.ActionForm;
   public class login_actionform extends ActionForm {
       private String username;
       private String passwors;
      public String getUsername() {
          return username;
            }
       public void setUsername(String username) {
           this.username = username;
                }
       public String getPasswors() {
                   return passwors;
                                    }
          public void setPasswors(String passwors) {
          this.passwors = passwors;
             }
         }

分享到:
评论

相关推荐

    ActionForm

    在Struts配置文件(struts-config.xml)中,我们需要定义ActionForm与Action的关联: ```xml <action path="/register" type="com.example.RegisterAction"> </action> ``` 这里,`RegistrationForm`是...

    Struts Hibernate Spring 集成开发宝典 actionform

    2. **配置Spring**: 创建Spring的配置文件,如applicationContext.xml,声明并配置所需的Bean,包括Action、ActionForm、SessionFactory等。 3. **整合Hibernate**: 在Spring配置文件中,配置Hibernate的...

    StrutsAction

    这个博客可能包含了如何创建Action类,定义ActionForm,配置struts-config.xml文件,以及如何编写相应的JSP页面等步骤。 7. **实际应用** 在实际开发中,StrutsAction的使用远不止于此,可能会涉及拦截器...

    手动编写struts源码及讲解

    在手动编写Struts源码的过程中,你将了解到如何创建Action类,如何定义ActionForm,以及如何在struts-config.xml中配置这些元素。这将帮助你理解请求是如何从浏览器到服务器,再到Action,最后到视图的整个流程。...

    Struts In Action.zip

    书中会详细讲解如何创建Struts应用,从最初的项目结构设定,到编写Action和ActionForm,再到配置struts-config.xml文件,以及如何使用Struts标签库进行视图渲染。此外,还会涵盖Struts与其他技术(如Hibernate、...

    struts in action 英文版

    Struts In Action 这本书会详细解释Struts的各个组件及其工作原理,包括Action、ActionForm、ActionMapping、RequestProcessor等。同时,书中也会涵盖如何配置Struts,如编写struts-config.xml文件,以及如何创建...

    Struts2框架ActionForm自动填充表单

    当你创建一个Action类并实现`ModelDriven`接口时,你需要定义一个模型对象,该对象将与表单字段进行绑定。例如,你可以创建一个名为`UserForm`的Java类,包含与表单对应的属性,如用户名(username)、密码...

    Struts In Action

    - **struts-config.xml:** 该文件是 Struts 应用的核心配置文件,用于定义 Action、ActionForm、ActionMapping 和 ActionForward 等元素。 - **web.xml:** 除了包含 Struts 必需的 Servlet 和过滤器配置外,还...

    struts编写的mailreader中文例子

    4. **ActionMapping**:定义了Action与URL的映射关系,以及ActionForm到Action的绑定。 5. **Tiles**:一种视图组装工具,允许开发者创建可重用的页面组件。 6. **Struts-config.xml**:Struts的配置文件,包含了...

    Struts In Action中文版

    ActionForm则负责在Action与视图之间传递数据,收集用户的输入。ActionServlet作为Struts的核心控制器,负责解析HTTP请求,调用相应的Action执行业务逻辑。 本书《Struts In Action》将详细讲解如何配置和使用这些...

    用struts和jsp编写的日志系统

    - **配置文件**:通常为struts-config.xml,定义了ActionMapping,ActionForm和Action的映射关系。 - **Action**:实现了Servlet API中的Action接口,负责处理请求并调用业务逻辑。 - **ActionForm**:用于收集和...

    struts框架代码

    struts-config.xml是Struts框架的配置文件,它定义了Action与ActionForm的映射、Action间的跳转规则以及国际化等设置。开发者需要在这个文件中详细配置每个Action类、表单Bean以及控制器的路径,确保请求能正确路由...

    struts入门小例子

    2. **ActionForm**:ActionForm 类用于封装用户从表单提交的数据,它与 Action 类协作,将数据传递到业务层。ActionForm 类继承自 `org.apache.struts.action.ActionForm`,并包含对应表单字段的属性。 3. **struts...

    struts 基础入门

    然后编写Action和ActionForm类,最后设计JSP页面作为视图。 五、实例解析 本教程中的“最简单的Struts例子”可能包含以下几个步骤: 1. 创建一个简单的Action类,实现execute方法,该方法处理请求并返回结果。 2. ...

    Struts基础电子书

    四、Action与ActionForm Action类是处理用户请求的Java类,每个Action对应一个业务操作。ActionForm用于封装表单数据,它继承自org.apache.struts.action.ActionForm,并通过getter和setter方法来存储和获取数据。 ...

    struts实现用户登录

    总结来说,使用Struts 1.2实现用户登录涉及到了MVC架构的理解,Struts配置文件的编写,ActionForm和Action类的设计,以及数据库操作和错误处理。虽然现代Web开发更倾向于Spring Boot和前端框架,但掌握Struts的基础...

    Struts_开发的最佳实践

    8. **测试驱动开发**:编写单元测试以确保Action和ActionForm的正确性,使用Mock对象模拟控制器和视图层。 9. **日志和异常处理**:适当配置日志系统,如Log4j,记录应用程序的运行状态和异常信息,以便于调试和...

    moke测试struts的action

    如果是配置文件,可能是Struts的配置文件(struts-config.xml或struts2的struts.xml),包含了Action的定义及其与视图和控制器的关联。 在深入探讨Struts Action时,我们需要了解以下关键点: 1. **Action配置**:...

    Struts in Action 源代码

    3. **JSP页面的使用**:查看JSP文件可以学习到如何使用JSTL、EL表达式来动态生成HTML内容,以及如何与ActionForm和Action进行交互。 4. **国际化和本地化**:Struts提供了支持多语言的功能,通过源代码可以学习如何...

    struts试验指导手册

    三、Action与ActionForm 1. **Action**:自定义的Action类需要继承`org.apache.struts.action.Action`,并重写execute方法。在execute方法中,你可以编写处理用户请求的业务逻辑,并根据结果返回对应的Forward。 2....

Global site tag (gtag.js) - Google Analytics