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
注意:
ServletRequest
和
ServletResponse
,
Http
中的是
HttpServletRequest
和
HttpServletResponse
对象。
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