result 相关

1.dispatcher

2.redirect

3.chain

4.redirectAction

5.freemarker

6.httpheader

7.stream

8.velocity

9.xslt

10.plaintext

11.tiles

常用的是前四种

<package name="resultType" namespace="/r" extends="struts-default">

        <action name="r1">
            <!-- result 不指定type默认为dispatcher 运用服务器跳转 forword到jsp压面 显示action地址 -->
            <result type="dispatcher">/r1.jsp</result>
        </action>

        <action name="r2">
            <!-- 客户端跳转 显示jsp地址 -->
            <result type="redirect">/r2.jsp</result>
        </action>

        <!-- 同r1 forword到另外一个action -->
        <action name="r3">
            <result type="chain">r1</result>
        </action>

        <!-- 同r2 -->
        <action name="r4">
            <result type="redirectAction">r2</result>
        </action>
    </package>

    <package name="user2" namespace="/user2" extends="struts-default">
        <!-- 其他包可以用extends继承 -->
        <global-results>
            <result name="mainpage">/main.jsp</result>
        </global-results>

        <action name="user2" class="com.ouc.wkp.action.UserAction2">
            <result name="success">/r1.jsp</result>
            <result name="error">/r2.jsp</result>
        </action>
    </package>

    <package name="user3" namespace="/user3" extends="struts-default">
        <action name="user3" class="com.ouc.wkp.action.UserAction3">
            <result>${r}</result>
        </action>
    </package>
struts.xml
package com.ouc.wkp.action;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction2 extends ActionSupport {
    private int type;

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public String execute() throws Exception {
        if(type==1){
            return "success";
        }else if(type==2){
            return "error";
        }else{
            return "mainpage";
        }
    }
}
UserAction2
动态结果集,在action中保存一个属性,存储具体的结果location
package com.ouc.wkp.action;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction3 extends ActionSupport {
    private int type;
    private String r;

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getR() {
        return r;
    }

    public void setR(String r) {
        this.r = r;
    }

    @Override
    public String execute() throws Exception {
        if (type == 1) {
            r = "/r1.jsp";
        } else if (type == 2) {
            r = "/r2.jsp";
        } else {
            r = "/main.jsp";
        }
        return SUCCESS;
    }
}
UserAction3

使用redirect跳转时是两次request,需要传参

<!-- <result type="redirect">/xxx.jsp?t=${type}</result> -->

前台通过<s:property value="#parameters.t"/>从actioncontext里面取

posted @ 2016-08-04 00:40  docyard  阅读(215)  评论(0编辑  收藏  举报