SetCharacterEncoding comprehension in encoding, setcharacterencoding
1. pageEncoding = "UTF-8" is used to set the encoding used when JSP is compiled into Servlet.
For data sending, the server will encode the data to be sent according to the priority of response. setCharacterEncoding-contentType-pageEncoding.
For the data submitted in POST mode in the form, as long as the request is correct in the JSP that receives the data. the setCharacterEncoding parameter is used to re-encode the client request and set it to browser encoding. This ensures that the obtained parameter encoding is correct. Some readers may ask how to get the browser code? As mentioned above, by default, browser encoding is the value set by response. setCharacterEncoding In the JSP page that responds to the request. Therefore, for the data submitted by the POST form, the request. setCharacterEncoding must be set to the same value as the response. setCharacterEncoding value on the JSP page that generates the submitted form.
For the data submitted by the URL and the data submitted by the GET method in the form, set the request in the JSP that receives the data. the setCharacterEncoding parameter does not work, because in Tomcat5.0, ISO-8859-1 is used by default to re-encode (decode) the data submitted by the URL and the data submitted by the GET method in the form ), this parameter is not used to re-encode (decode) the data submitted by the URL and the data submitted by the GET method in the form ). To solve this problem, set the useBodyEncodingForURI or URIEncoding attribute in the Tomcat ctor tag of the Tomcat configuration file. The useBodyEncodingForURI parameter indicates whether to use the request. the setCharacterEncoding parameter re-encodes the data submitted by the URL and the data submitted by the GET method in the form. By default, this parameter is false (the default value is true in Tomcat4.0 ); the URIEncoding parameter specifies the uniform re-encoding (Decoding) of all GET requests (including data submitted by URL and data submitted by GET in the form. The difference between URIEncoding and useBodyEncodingForURI is that URIEncoding uniformly recodes (decodes) the data of all GET requests, while useBodyEncodingForURI is based on the request on the page responding to the request. the setCharacterEncoding parameter re-decodes data. Different pages can have different re-encoding (Decoding) codes. Therefore, you can modify URIEncoding to browser encoding or useBodyEncodingForURI to true for URL-submitted data and GET-submitted data in the form, and request data on the JSP page that obtains data. the setCharacterEncoding parameter is set to browser encoding.