SetCharacterEncoding comprehension in encoding, setcharacterencoding

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.