Explanation of Uriencoding and Usebodyencodingforuri __javaee

Source: Internet
Author: User

Http://tomcat.apache.org/tomcat-7.0-doc/config/http.html

Check the official documents, like the following table

Uriencoding

This specifies the "character encoding used to decode" URI bytes, after%xx decoding the URL. If not specified, iso-8859-1 'll be used.

Usebodyencodingforuri

This is specifies if the encoding specified in ContentType should is used for URI query parameters, instead of using the Urie Ncoding. This setting was present for compatibility with Tomcat 4.1.x, where the encoding specified in the ContentType, or explicitl Y set using Request.setcharacterencoding method is also used for the "parameters from" URL. The default value is False.

NOTES:1) This setting are applied only to the query string of a request. Unlike uriencoding it does not affect the path portion of a request URI. 2) If request character encoding is not known (isn't provided by a browser and be not set by Setcharacterencodingfilter O R A similar filter using request.setcharacterencoding method), the default encoding is always "iso-8859-1". The uriencoding setting has no effect on this default.


Google translation:

Uriencoding

Decodes the%xx portion of the URI with the specified encoding, and if not specified, the default is Iso-8859-1. if the Chinese in the URI is not converted to the%XX format by Encodeurl encoding, but rather the normal encoding, that is, encoding without adding additional% characters, the final decoding is also used iso-8859-1

Usebodyencodingforuri

This specifies whether the encoding specified in ContentType applies to URI query parameters instead of using uriencoding. This setting is used for Tomcat 4.1.x compatibility, where the encoding specified in contenttype or an encoding that is explicitly set using the Request.setcharacterencoding method also applies to parameters from the URL. The default value is False.


Note: 1 This setting applies only to the requested query string. Unlike uriencoding, it does not affect the path portion of the request URI. 2 if the request character encoding is unknown (not provided by the browser, rather than by Setcharacterencodingfilter or a similar filter set using the Request.setcharacterencoding method), the default encoding is always " Iso-8859-1 ". The uriencoding setting has no effect on this default value.




Using Chrome to access http://localhost:8081/Charset/CharsetServlet/Junshan author= Junshan

View by F12

Http://localhost:8081/Charset/CharsetServlet/%E5%90%9B%E5%B1%B1?author=%E5%90%9B%E5%B1%B1

The Chinese and querystring in the URI are found to be utf-8 encoded by analysis. I tested in other browser Firefox to find that the URI and QueryString, if contained in Chinese, still use utf-8 encoding. But I read books and read blogs and found that different browsers have different encodings for the Chinese in both the URI and QueryString, such as the URI is UTF-8 encoding, and QueryString is the GBK encoding. I guess the browser version is now upgraded to unify the two coding methods.


However, in practical applications, we still need to know that the two parts of the URI and querystring in the Chinese browser can be encoded in a different way.

And the HTTP requests we send are usually get,post.

If you are using GET, it is best to find Servlet.xml in Tomcat's conf directory:

1. Set uriencoding= "CharsetName", the server in the URI of Chinese and querystring in Chinese to use this specified encoding and decoding (the premise is encoded in Chinese is the form of%xx, which is encoded in front of each byte plus the format, such as the encodeURI after the format), if it is not still using Tomcat default iso-8859-1 decoding, so there may be garbled.

2. Set uriencoding= "Cahrsetname" usebodyencodingforuri= "true". If Usebodyencodingforuri is set to true, the decoding of QueryString takes the encoding specified in the Content-type in the request header or the request.setsetcharacterencoding ( CharsetName), the encoding specified in the default method is only useful for post. But if no encoding is specified in either Content-type or Content-type, and the encoding is not set through Request.setsetcharacterencoding (CharsetName), Default or will use Iso-8859-1 decoding querystring, so here may also produce garbled


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.