[转] Solve the issue of Tomcat5.0.19 Chinese parameters

zhaozj2021-02-16  127

Author: Elves

Published: 2004-04-14 02:07 Original: http://www.javaworld.com.tw/jute/post/view? Bid = 9 & id = 44042 & sty = 3 & agn = 0 & tpg = 1 & ppg = 1 # 44042 actually use Tomcat 5.0 .19, we understand that in the case of not modifying the original code of Tomcat, the user will be treated with ISO8859-1 through form 6859-1, and the programming designer must convert the string to BIG5 (Traditional Chinese) or GB2312 / GBK. (Simplified Chinese), in the application, for all Request.GetParameter ("XX"); do Tobig5String () processing, in theory, all Chinese issues should not appear, result, or find some In some cases, Chinese still become garbled! After analyzing, we found the problem in querystring analysis, before in Tomcat 4.x era, regardless of Submit, Tomcat Server's processing of Parameters, but in Tomcat 5.x, I don't know Here, it is independent of QueryString's analysis. Currently, Form's Method uses GET and directly writes the parameters on the URL. When you upload to Tomcat, no matter how to turn, it will become garbled, then you have made Urlencode in advance. The same is true. On the website, some people suggest that all Chinese will be changed with Base64 encoding, and the program will come back to SERVER, and ensure that Chinese will not have problems. This way can of course solve this problem, but all the web pages turn to a limited POST, and the program designer should clearly clearly, that parameter is uploaded by Get, which parameter is uploaded by POST, and then uses different parsing in different ways. Such a program is not a little transplantability, let alone the platform, cross international language. To study the documentation and original code of Tomcat, we found the problem with the problem and the solution, only the following practices can make the form 6859-1 code, of course, if it is a full photo description of Tomcat Going, definitely not, you have to add this parameter to server.xml.

The solution is planned to study $ Tomcat_home / webapps / tomcat-docs / config / http.html, the recording focus is as follows: uriencoding: this specifies the character Encoding use to decode the Uri Bytes, after% xx decoding the URL. IF not specified, ISO-8859-1 will be used 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. Tomcat said two parameters, is set in the server.xml, http region Block, to solve querystring Chinese to become garbled, you must set at least one of these two parameters. Uriencoding Please set to uriencoding = "ISO-8859-1" specified as "ISO-8859-1" encoding, let QueryString's characterization is the same as Post Body. UsebodyEncodingForuri This is used to compath the Tomcat 4.x. The setting value is "true" or "false", meaning "Do you want QueryString with the POST BODY to use the same character code?", if it is set to True It can also reach the demand for "ISO-8859-1" encoding. It is recommended to use Uriencoding settings, after all, UsebodyEncodingForuri's practice is to compatible Tomcat 4.x. However, if the original instructions are theoretically, the two parameters are not set. Tomcat should also use "ISO-8859-1" code, why will there be a problem? We are clear by Tomcat Source Code.

// This code is Tomcat to solve the querystring program, // in org.apache.tomcat.util.http.parameters this class. private String urlDecode (ByteChunk bc, String enc) throws IOException {if (urlDec == null) {urlDec = new UDecoder ();} urlDec.convert (bc); String result = null; if (! enc = null) {bc stencoding (ENC); Result = bc.toString ();} else {charchunk cc = tmpnamec; cc.allocate (bc.getLength (), -1); // default encoding: fast conversion Byte [] bbuf = BC. GetBuffer (); char [] CBUF = cc.getBuffer (); int start = bc.getStart (); for (int i = 0; i

Setting example of Connector:

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

New Post(0)