码迷,mamicode.com
首页 > 其他好文 > 详细

result 相关

时间:2016-08-04 01:28:09      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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里面取

result 相关

标签:

原文地址:http://www.cnblogs.com/wangkaipeng/p/5735137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!