Why does POST not honor charset, but an AJAX request does? tomcat 6

后端 未结 5 797
攒了一身酷
攒了一身酷 2020-12-05 07:29

I have a tomcat based application that needs to submit a form capable of handling utf-8 characters. When submitted via ajax, the data is returned correctly from getParameter

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 07:50

    Try this :

    How do I change how POST parameters are interpreted? 
    

    POST requests should specify the encoding of the parameters and values they send. Since many clients fail to set an explicit encoding, the default is used (ISO-8859-1). In many cases this is not the preferred interpretation so one can employ a javax.servlet.Filter to set request encodings. Writing such a filter is trivial. Furthermore Tomcat already comes with such an example filter.

    Please take a look at:

    5.x
    
    webapps/servlets-examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java
    
    webapps/jsp-examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java
    
    6.x
    
    webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java
    

    For more info , refer to the below URL http://wiki.apache.org/tomcat/FAQ/CharacterEncoding

提交回复
热议问题