经过一晚上的努力,终于把这个问题解决了,现在和大家一起分享下!
一、传递参数的实现:从survey.action跳转到 student.action
在survey.action中有message 这样一个参数需要在重定向之后传递到下一个student.action中,则在survey.action中给message赋值,并保证survey.action中message有get,set方法,在student.action中仍然要有get,set方法:
<result name="surveyDone" type="redirect">
<param name="location">student.action?msg=${message}</param>
<param name="encode">true</param>
</result>
(注意:此处最好使用<param>标签,这种<result name="surveyDone" type="redirect">student.action?msg=${message}</result>好像时实现不了,,,,,)
二、struts2重定向中文参数乱码问题:
Struts2整个项目都是用utf-8编码,redirect跳转时url被"ISO-8859-1"重新编码了,所以到了下一个action成了乱码。在下一个action中处理转换这个信息
在目标student.action中获取参数message时,采用以下方法(注意在student.action中仍然要有get,set方法):
try {
if (message != null) {
message = new String(msg.getBytes("ISO-8859-1"), "UTF-8");
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}