Tomcat5.0.19 POST and GET Chinese Solution

xiaoxiao2021-03-06  55

First excerpt $ TOMCAT_HOME / webapps / tomcat-docs / config / http.html two parameters explained: URIEncoding:. This specifies the character encoding used to decode the URI bytes, after% xx decoding the URL If not specified, ISO- 8859-1 Will BE.

useBodyEncodingForURI: This specifies if the encoding specified in contentType should be used for URI query parameters, instead of using the URIEncoding This setting is present for compatibility with Tomcat 4.1.x, where the encoding specified in the contentType, or explicitely set using Request.. Setcharacterencoding method Was Also Used for the parameters from the url. The default value is false.

The two TOMCAT parameters described above are the HTTP area set in Server.xml. To resolve QueryString Chinese garbled, you must set at least one of the two parameters. Uriencoding Please set to uriencoding = "ISO-8859-1" specified as "ISO-8859-1" encoding, let QueryString the character encoding and post body. UsebodyEncodingForuri This is used to compath the Tomcat 4.x, the set value is "true" or "false", meaning "Do you want querystring to encode the same byte with the POST Body?", if it is set True, which can also reach the "ISO-8859-1" encoding needs. It is recommended to use Uriencoding settings, after all, UsebodyEncodingForuri's practice is to compatible Tomcat 4.x. However, if the original instructions are theoretical, the two parameters are not set. Tomcat should use "ISO-8859-1" encoding, then why do you have any questions? It is because of Tomcat Source Code About querystring programs BUG, so, or must be in Server.xml, plus the parameter setting of urlencoding. Setting example of Connector:

I have made several additions here ... Generally, we use the Tomcat 4 to pass parameters through the parameters of the GET or POST, usually use the Filter to solve the problem of Chinese transmission parameters. However, after tomcat 5.0.19, when solving the Chinese transfer parameters, it must be considered to use GET or POST, and two solutions are different. If it is passed using a GET, it is as described in the art of the Elvous Brother, or use String Name1 = New String (Request.getParameter ("Name"))). GetBytes ("ISO-8859-1"), "GB2312 ");; If you use the POST's way, it is extended to the traditional way to solve Chinese. Request.SetCharacterencoding (" BIG5 "); but the last way to use the Filter's way Filter is: first judgment is used Get or POST, if the way is used in the way, the first Code is used; if the POST mode is used, the second Code is used.

In addition, solving POST can also be used to use Filter to resolve:

1 Implement a Filter. Set the processing character set to GBK. (There is a complete example in Tomcat's WebApps / Servlet-Examples directory. Please refer to Web.xml and SetcharacterencodingFilter.)

First add: <% @ Page ContentType = "text / html; charset = GB2312"%>

1) Just copy the% Tomcat installation directory% / webApps / servlets-example / web-inf / class / filter.class file to copy your webapp directory / filters, if there is no Filters directory, create one.

2) In your web.xml, add the following lines:

转载请注明原文地址:https://www.9cbs.com/read-114821.html

New Post(0)