action 交互到带命名空间的action 还有返回的jsp

代码:
不带命名空间的2个action的交互,

package com.act;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
@ParentPackage("struts-default")
public class reTest1 extends ActionSupport {
@Override
public String execute() throws Exception {
    // TODO Auto-generated method stub
    return super.execute();
}
@Action(value="res_1",results={@Result(type="redirectAction",location="res_2")})
public String res_1() throws Exception {
    System.out.println("res_1------------->>");
    return SUCCESS;
}
@Action(value="res_2",results={@Result(type="redirectAction",location="res_1_1",params={"namespace","/test"})})
public String res_2() throws Exception {
    System.out.println("res_2------------->>");
    return SUCCESS;
}
}

然后由第二个action重定向到带命名空间的action
那就需要params={"namespace","/test"}配上这个
或者将地址改成如下:

location="test/res_1_1"
package com.act;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
@ParentPackage("struts-default")
@Namespace("/test")
public class reTest2 extends ActionSupport {
    @Action(value="res_1_1",results={@Result(type="redirectAction",location="res_2_2")})
    public String res_1() throws Exception {
        System.out.println("res_1_1------------->>");
        return SUCCESS;
    }
    @Action(value="res_2_2",results={@Result( type="redirect",location="../res_1.jsp")})
    public String res_2() throws Exception {
        System.out.println("res_2_2------------->>");
        return SUCCESS;
    }
}

两个JSP没贴。没什么
我的工程配置了/路径的。
至于JSP的返回../res_1.jsp。本来是在test路径下,然后../就到了根路径下??大神救我~~
这是返回的结果:
res_1————->>
res_2————->>
res_1_1————->>
res_2_2————->>

下面的代码是从命名空间传出来

package com.act;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
@ParentPackage("struts-default")
public class reTest1 extends ActionSupport {
@Override
public String execute() throws Exception {
    // TODO Auto-generated method stub
    return super.execute();
}
//这里默认的工作空间是根,我在配置文件里面配置了一句
@Action(value="res_1",results={@Result(type="redirect",location="res_2.jsp")})
public String res_1() throws Exception {
    System.out.println("res_1------------->>");
    return SUCCESS;
}
@Action(value="res_2",results={@Result(type="redirectAction",location="res_1")})
public String res_2() throws Exception {
    System.out.println("res_2------------->>");
    return SUCCESS;
}
}

带命名空间的往外传数据请求

package com.act;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
@ParentPackage("struts-default")
@Namespace("/test")
public class reTest2 extends ActionSupport {
    @Action(value="res_1_1",results={@Result(type="redirectAction",location="res_2",params={"namespace","/"})})
    public String res_1() throws Exception {
        System.out.println("res_1_1------------->>");
        return SUCCESS;
    }
    @Action(value="res_2_2",results={@Result( type="redirectAction",location="res_1_1")})
    public String res_2() throws Exception {
        System.out.println("res_2_2------------->>");
        return SUCCESS;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值