• 2004-04-05

    Struts中的Action类

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://pcmanlin.blogbus.com/logs/129180.html

    Action

    Action类对于每一个特定的Struts功能都要被继承。Action类的集合定义了你的Wen应用程序。

     

    execute() 方法

    这是应用程序真正逻辑开始的地方,你需要重写这个方法来定义自己的Action子类。两个execute()方法:

    1)一个execute方法实现在自定义非Http协议的Action时使用,它给人的感觉类似于GenericServlet类。

    public ActionForward execute(ActionMapping mapping,

           ActionForm form,

           ServletRequest request,

           ServletResponse response)

           throws IOException, ServletException

    注意:ServletRequestServletResponseHttp中的是HttpServletRequestHttpServletResponse对象。

    2)还有一个就是Http协议的execute方法了,类似于HttpServlet类。

    public ActionForward execute(ActionMapping mapping,

           ActionForm form,

           HttpServletRequest request,

           HttpServletResponse response)

           throws IOException, ServletException

    ActionMapping 包含了某个Action bean的配置信息,这个类用于确定处理完成后,前往的地方。

     

    ActionForm 代表来自视图的表单输入(包含了请求参数),这个引用会被传递给ActionForm子类的实例。

     

    HttpServletRequest 指向Http请求对象的引用。

     

    HttpServletResponse 指向Http回应对象的引用。

     

    继承Action

    以下步骤:

    1)创建一个继承自Action的子类

    2)实现execute()方法,然后指定你的业务逻辑

    3)编译这个类,然后将它移到Web应用程序的classpath目录下

    4)将<action>元素加到应用程序的struts-config.xml文件中,描述新的Action


    历史上的今天:

    Struts 控制器 2004-04-05

    收藏到:Del.icio.us




    引用

    下面Blog引用了该文: