Struts 2 入门 二(Struts2 Action配置)
<package name="default" namespace="/" extends="struts-default">
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
首先要先定义 一个 包 必须继承 struts-default
action 常用属性:
name: 必须
class: 不是必须 默认是ActionSupport
method: 不是必须 默认是 execute
Result 常用属性:
name: 不是必须 默认是 SUCCESS
type:不是必须 默认是 dispatcher
Struts 源码
If the class attribute in an action mapping is left blank, the com.opensymphony.xwork2.ActionSupport class is used as a default.
如果类属性在一个操作映射为空白,com.opensymphony.xwork2。ActionSupport类作为一个默认的。
Another common workflow stategy is to first render a page using an alternate method, likeinput and then have it submit back to the default execute method.
默认方法 execute
Setting a default Result Type
(设置一个默认的结果类型)
<result-types>
<result-type name="dispatcher" default="true"
class="org.apache.struts2.dispatcher.ServletDispatcherResult" />
</result-types>
Likewise if the name attribute is not specified, the framework will give it the name "success".
(同样,如果没有指定名称属性,该框架将给它命名为“success”。)
dispatcher和Forward 都是 请求转发 也是 服务器端跳转
redirect 是重定向 客户端跳转