struts2中action跳转action传值问题
struts配置文件中写法如下
action1:
<action name="test" class="testAction">
<result name="suc1" type="redirectAction">/test2!m1?id=${id}&status=${status}</result>
</action>
action2:
<action name="test2" class="test2Action">
<result name="suc2">index.jsp</result>
</action>
java代码 action1:
public String test(){
...
request.setAttribute("id" , 1);
request.setAttribute("status" , 0);
return suc1;
}
action2:
public String m1(){
...
int id = request.getParameter("id");
int status = request.getParameter("status");
}
问题是id和status都取不到值,是什么原因啊,还是哪里要设置了?
[解决办法]
把id和status都定义为action2类的属性,添加get和set方法,然后再m1中使用。
action2:
private int id;
private int status;
public String m1(){
...
int id = this.getId();
int status = this.getStatus();
}
public int getId(){
return id;
}
public int getStatus(){
return status;
}
public void setId(int id){
this.id=id;
}
public void setStatus(int status){
this.status=status;
}
[解决办法]
type="redirect" 这样试试 ,我以前是这样用的 ,还是升级了?
int status = request.getParameter("status");
这个应该报错吧 返回的字符串 直接赋给int型变量,你这能正常走到action2吗?