Spring MVC参数传递中文乱码解决方案
2017-02-05 12:03
197 查看
Spring MVC参数传递中文乱码解决方案
Spring MVC参数传递中文乱码解决方案概述
GET提交中文乱码解决方案
POST提交中文乱码解决方案
概述
中国特色社会主义乱码问题是我们经常会碰到的问题,解决的办法有很多,本文分别介绍了GET方式和POST方式中文乱码解决方案中一劳永逸的办法。GET提交中文乱码解决方案
在乱码的Controller文件中采用下面的方法将编码转换成UTF-8String str = new String(request.getParameter("参数名").getBytes("iso-8859-1"), "utf-8");
修改项目所在的Tomcat服务器中的server.xml文件
将
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
修改为:
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
对于Ajax请求的GET方式中文乱码问题用上述方法仍然能够解决。
POST提交中文乱码解决方案
在web.xml文件中添加下面的内容:<!-- 解决POST提交中文乱码问题的过滤器,注意只能解决POST提交中文乱码的问题 --> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
相关文章推荐
- 关于容器内URL传递中文参数乱码的解决方案
- jsp的url传递中文参数乱码解决方案,linux测试可用
- javascript通过url向jsp页面传递中文参数导致乱码解决方案
- Struts2中使用GET方式传递中文参数出现乱码的解决方案
- js用链接传递中文参数到servlet时 乱码的解决方案
- 静态页面html之间传递中文参数出现乱码问题的解决方案
- IE7、IE8下使用escape、encodeURI传递中文参数乱码的问题及解决方案
- ios--网页js调用oc代码+传递参数+避免中文参数乱码的解决方案(实例)
- ios--网页js调用oc代码+传递参数+避免中文参数乱码的解决方案(实例)
- ios--网页js调用oc代码+传递参数+避免中文参数乱码的解决方案(实例)
- URL传递中文参数中乱码问题的解决方案
- jquery ajax传递中文参数乱码问题及解决方案
- javascript通过url向jsp页面传递中文参数导致乱码解决方案
- ios--网页js调用oc代码+传递参数+避免中文参数乱码的解决方案(实例+demo)
- javascript通过url向jsp页面传递中文参数导致乱码解决方案
- jsp的url传递中文参数乱码解决方案,linux测试可用
- ios--网页js调用oc代码+传递参数+避免中文参数乱码的解决方案(实例)
- jsp中url传递中文参数乱码的暂时解决方案
- spring MVC笔记3——传递参数和解决中文乱码
- Spring MVC url 参数传递出现中文乱码解决方法