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;
    }
}

你可能感兴趣的:(jsp,struts,namespace,action,params)