response.setContentType與 request.setCharacterEncoding 區別
阿新 • • 發佈:2018-12-30
http://blog.csdn.net/joywy/article/details/8006645
ps1:最初的版本只有response.setContentType,後來被request.setCharacterEncoding替代了。
ps2:request只對post有效果。
ps3:request.setCharacterEncoding和response.setCharacterEncoding等同於spring的
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- <init-param>
- <param-name>forceEncoding</param-name>
- <param-value>true</param-value>
- </
</filter>
encoding只是設定了request的編碼格式,即在Servlet中:
request.setCharacterEncoding("XXXX");
如果設定forceEncoding的值為true時,相當於Servlet中:
request.setCharacterEncoding("XXXX");
response.setCharacterEncoding(“XXXX”);
forceencoding預設值為false