action的结果处理器

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值