struts 重定向传参中文乱码问题解决方案

来源:互联网 发布:windows sever 2003 编辑:程序博客网 时间:2024/05/16 12:23

出现中文乱码的原因:

           Struts2整个项目都是用utf-8编码,redirect跳转时url被"ISO-8859-1"重新编码了,所以到了下一个action成了乱码。在下一个action中处理转换这个信息

解决思路:

        在action中对重定向传回的参数进行"UTF-8" 重新编码。

方案1:

  struts.xml代码:

<result name="reload" type="redirect"><param name="location">/kyssl/ovopen3?message=${message}&amp;aaa=${aaa}</param><param name="encode">true</param></result>

 action代码:

try {if (message != null) {message = new String(message.getBytes("ISO-8859-1"), "UTF-8");}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}

方案2:

 struts.xml代码:

<result name="reload" type="redirectAction"><param name="actionName">ovopen3</param><param name="namespace">/kyssl</param><param name="message">${message}</param><param name="encode">true</param></result>
 action代码:

try {    if (message != null) {          message = URLDecoder.decode(message, "utf-8");    }} catch (Exception e) {    // TODO Auto-generated catch block    e.printStackTrace();}


原创粉丝点击