tomcat的server.xml中的UrIEncoding编码设置

来源:互联网 发布:alpha软件 编辑:程序博客网 时间:2024/06/03 14:16
如果设置了其为中文编码格式,只对get方法有效,但是post方法就不可以了,因为这个属性本来就是设置了get时候的数据编码,如何使它对post也有作用呢?

引用
This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.

官方文档中的说明,该编码指定的是为URI进行解码用的,只对GET请求有效,POST请求参数是以http body形式提交的,不会受此影响。如果需要对POST指定编码,你可以使用EncodingFilter这样是实现,比如spring就提供了一个
Java代码  收藏代码
  1. <filter>  
  2.  <filter-name>characterEncodingFilter</filter-name>  
  3.  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  4.  <init-param>  
  5.   <param-name>encoding</param-name>  
  6.   <param-value>utf8</param-value>  
  7.  </init-param>  
  8. </filter>  

放在所有filter的第一个就好了

post数据只需要在截取或者过滤器中实现编码转换一般就不会有问题,而get,通过地址栏提交,这种方式在本质上就容易出现编码问题。这个其实也是为什么我们经常说post提交数据安全完整的原因。你看UrIEncoding这个属性的意思就是UrI的编码,刚好是针对get这种地址参数的。所以基本上不用考虑对post起作用。
0 0
原创粉丝点击