日期:2014-05-17  浏览次数:20698 次

sturts2利用action传值为什么得不到值呢?帮我看看哪出错了,谢谢
login.jsp 中login.action 出发action


配置文件
<package name="login" namespace="/" extends="struts-default">
<action name="login" class="cn.com.action.Test" method="login">
 
<result name="success" type="chain">
<param name="bb">${bb}</param>  
<param name="actionName">test</param>
<param name="namespace">/</param>
</result>

</action>
 
<action name="test" class="cn.com.action.Test" method="test">
<result name="success">/welcome.jsp</result>
</action>

</package>


Test.java

public class Test extends ActionSupport {

private int bb;
public String login() throws Exception{

bb=11;
return "success";

}

public String test() throws Exception{

return "success" ;
}


public int getBb() {
return bb;
}

public void setBb(int bb) {
this.bb = bb;
}

welcome.jsp

  <body>

${bb}
  </body>

代码已经贴上,是哪的问题,bb就是获得不了。如果将type="chain" 改成 type="redirectAction"就可以得到,这个是怎么回事啊,怎么该啊?谢谢。

------解决方案--------------------
那你就是使用action,跳转到action中,那么《resutl>标签中就要使用重定向到action中,type="redirectAction",就要使用这个标签
------解决方案--------------------
我的理解是 : chain 和 forward一样 url显示login 其实执行的 test()方法 而 redirectAction 是去执行 login()方法。 你可以打断点看看 是否执行了 login(); 否则bb没有值