Struts2 中文乱码

来源:互联网 发布:淘宝行业数据 编辑:程序博客网 时间:2024/05/18 03:03

   环境:   struts包版本:struts-core-2.1.6

                   filter配置:

                  JSP页面均已配置:contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"

                   struts.xml 无论是否加入: <constant name="struts.i18n.encoding" value="GBK" />

   过程:通过index页面上form表单向result页面发送中文字符请求

   结果

                method="GET"          乱码              无论是form中设置method还是浏览器输入

                method="POST"      正确中文    



   总结:在web.xml中,将struts2配置为org.apache.struts2.dispatcher.FilterDispatcher时,post请求均可很好的自动解决中文乱码问题,get一律报错(在不借助其他方法进行手动重编码的情况下)

             在web.xml中,将struts2配置为org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter时,无论如何中文均报BUG,据官方解释此为BUG,  struts 2.1.7后进行了修复

  结论: 在2.1.7之前,结果中文乱码问题,最好自行编写CharactorEncodingFilter进行编码。

              若试图使用上述中的FilterDispatcher解决中文问题,则会连带产生由于Filter版本不同而带来的多种问题,其一便是自定义Action中利用ActionContext.getContext.get("request")引发空指针的问题

   

相关资源:http://topic.csdn.net/u/20081029/14/ea380205-ae9a-4ad0-9a7d-5ab1b09a1908.html


原创粉丝点击