解决tomcat页面跳转中文乱码问题

参考:http://blog.itpub.net/29254281/viewspace-1073278/

http://cmsblogs.com/?p=1510



乱码问题汇总:


1> 在tomcat的server.xml设置<Connector URIEncoding=”utf-8”  />, 使用utf8对URI中出现的中文进行decode,例如http://localhost:8080/test/测试.do -> http://localhost:8080/test/%E6%B5%8B%E8%AF%95.do, 这样能够找到对应的controller方法。若不设置使用默认值ISO-8859-1


2> 在tomcat的server.xml设置<Connector useBodyEncodingForURI=”true”  /> 能够解决query String的乱码问题。
useBodyEncodingForURI=true -> 使用http header中指定charset进行decode(例如:Content-Type: charset=UTF-8),若未指定,则使用默认值ISO-8859-1
useBodyEncodingForURI=false -> 使用默认值ISO-8859-1


3> 若只配置了URIEncoding=”utf-8”,则query string的编码也会被设置为utf-8,且http header中设置的charset不会重写这个编码。若同时设置了两项,则对于query string的编码,则与设置useBodyEncodingForURI=true的作用是一样的(会被http header中的charset重写)


4> 建议使用utf-8为主,可以在web.xml 中配置encoding filter来指定默认的编码为utf-8,避免乱码问题的出现。
 <filter>
    <filter-name>encoding_filter</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>encoding_filter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值