action的结果处理器

来源:互联网 发布:三星高通9008端口救砖 编辑:程序博客网 时间:2024/06/10 05:51

action中的结果处理器如下(struts-core.jar/struts-default.xml):

<result-types>/            <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>            <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>            <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>            <result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>            <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>            <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>            <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>            <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>            <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>            <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />        </result-types>

其中:chain:代表转发到某一个动作
dispatcher:转发(默认值)
redirect:重定向
redirectAction:重定向到某个动作
如果我们要处理某一个属性的时候,不知道有没有该属性的setter方法
我们可以找该结果处理器所对应的类,在outline里面看看有没有相应的setter方法即可。

result的写法有两种:
1:<result name="success" type="dispatcher">a5</result>

2:<result name="succecc" type="dispatcher">
<param name="actionName">a5</param>

当我们遇到要访问不同包的时候,第二种方式就派上用场,同时还要在制定的包名前面写上相应的名称空间

    <package name="ansel4" extends="struts-default" namespace="/ns4">        <action name="a5">            <result name="success" type="redirectAction">                <param name="namespace">/ns5</param>                <param name="actionName">a6</param>            </result>        </action>

同时,我们还可以给action设置值,只有当我们的相应action类里面,定义了相关的setter方法:

public class sayHi extends ActionSupport implements Serializable {    private String message;    public String say(){        message="wwwwwwwwwwwwwwwwwwwwwwww";        return "success";    }    public String getMessage() {        return message;    }    public void setMessage(String message) {        this.message = message;    }}

此时给message设置值,应该这样写

这里写代码片
<package name="ansel7" extends="struts-default" namespace="/ns7">    <action name="a8" class="cn.ansel.domain.sayHi">        <param name="message">aha!</param>        <result name="success" >/9.jsp</result>    </action></package>

然后下面是获取message的值

    <package name="ansel8" extends="struts-default" namespace="/ns8">        <action name="a9" class="cn.ansel.domain.sayHi" method="say">            <result name="success" type="redirect">                /10.jsp?msg=${message}            </result>        </action>    </package>
0 0
原创粉丝点击