How does URIEncoding = 'UTF-8' work?

て烟熏妆下的殇ゞ 提交于 2019-12-02 19:19:25

问题


When I view the tomcat source code at http://grepcode.com/file/repo1.maven.org/maven2/org.apache.tomcat/tomcat-catalina/7.0.0/org/apache/catalina/connector/Request.java#Request.parseParameters%28%29 I can't find where to set encoding for the queryString which comes from get method and how does the configuration URIEncoding="UTF-8" in server.xml work in this method.


回答1:


The URIEncoding parameter is what you're looking for. It sets the character encoding to be used when URI decoding the query string.

You use it in server.xml as an attribute of the Connector entity.

If successfully used it in the past.




回答2:


First, let's use a more recent version of Tomcat. 7.0.0 is years old: Request.java from Tomcat 7.0.34

Second, the parseParameters method does not set the encoding: it fetches the encoding which has been set by other components. Some places where the content encoding might have been set:

  1. The URIEncoding of the connector (defaults to ISO-8859-1 AS per HTTP RFC)
  2. The request body encoding (from the HTTP request's Content-Type header)
  3. Another component -- perhaps sniffing the encoding by looking at a parameter's value

If you just want to set the URI encoding to UTF-8 unconditionally across your site, then just use the URIEncoding attribute in your <Connector>.

The direct answer to your question is that server.xml's URIEncoding attribute does not work in this method: it works elsewhere.



来源:https://stackoverflow.com/questions/14054454/how-does-uriencoding-utf-8-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!