1. 程式人生 > >response.setContentType與 request.setCharacterEncoding 區別

response.setContentType與 request.setCharacterEncoding 區別

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>
        

  1. <init-param>
  2.            <param-name>encoding</param-name>
  3.            <param-value>UTF-8</param-value>
  4.        </init-param>
  5.        <init-param>
  6.            <param-name>forceEncoding</param-name>
  7.            <param-value>true</param-value>
  8.        </
    init-param>

    </filter>

encoding只是設定了request的編碼格式,即在Servlet中:

        request.setCharacterEncoding("XXXX"); 

       如果設定forceEncoding的值為true時,相當於Servlet中:

       request.setCharacterEncoding("XXXX");

       response.setCharacterEncoding(“XXXX”); 

forceencoding預設值為false