首页 > 编程语言 > 详细

SpringMvc参数绑定出现乱码解决方法

时间:2016-10-19 01:50:31      阅读:241      评论:0      收藏:0      [点我收藏+]

在SpringMvc参数绑定过程中出现乱码的解决方法

1、post参数乱码的解决方法

在web.xml中添加过滤器

<!-- 过滤器 处理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>

2、处理get参数的乱码有两种 

一种是在Tomcat的配置文件中 修改

<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

二是对参数进行重新编码

String userName=new String(request.getParamter("userName").getBytes("ISO-8859-1"),"utf-8");

ISO-8859-1是tomcat的默认编码 需要将tomcat编码后的内容按utf-8编码

 

SpringMvc参数绑定出现乱码解决方法

原文:http://www.cnblogs.com/mrluotong/p/5975472.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!