JSP Chinese problem summary

xiaoxiao2021-03-06  42

Chinese problem summary

1, the page HTML static part garbled, such as the name of the form

Add between

2, page JSP dynamic part garbled

<% @ Page ContentType = "Text / HTML; Charset = GB2312" Language = "JAVA">

3, URL parameters receive Chinese garbled

Receive the servlet to join Request.setCharacterencoding ("GB2312"); you need to call before the read request parameter and INPUT readReader ().

4, mysql database operation garbled

Add Useunicode = true & characterencoding = GB2312:

JDBC: mysql: // Host / DatabaseName? Useunicode = true & characterencoding = GB2312 "

Specify the encoding when building a table

The following items in the page and the servlet are subject to 3 before submitting the database processing.

5, garbled when servlet forwarded

Display garbled or forwarded in the servlet requires calling before the operation:

Response.setContentType ("text / html; charset = GBK");

At the same time, it is followed by 1, 2 in the JSP page.

6. Transcoding method, the data of the request parameter or the data written to the database, is called when needed.

Public static string tochinese (String Constr)

{

Try {

IF (constr == null)

Return NULL;

Else

{

Constr = new string (constr.getbytes ("ISO8859_1"), "GBK");

Return constr;

}

} catch (exception e) {

Return NULL;

}

}

7. Change Tomcat's server.xml makes Chinese in the URL in the GET method also use GBK encoding.

If you find that the SUBMIT method is transmitted in the Submit method in the form, the Chinese pass to the server or not normal display, but the POST method can be encoded by the method described above, which may be in Tomcat4 There is no, but in Tomcat5, it is because Tomcat4 and Tomcat5 are different from QueryString (GET Method) and post methods, and POST and QueryString are the same encoding method in Tomcat4, if not explicit Specifies whether the default is ISO-8859-1, but the POST is POST default is ISO-8859-1, QueryString defaults to%? "Instead of ISO-8859-1.

Therefore, it is necessary to display the encoding mode of the QueryString, find the block in Tomcat_Home / Conf / Server.xml, and set one of these two parameters.

Uriencoding: Specifies QueryString Coding

UserEncodingForuri: True Specifies Uriencoding Coding as POST, FALSE is the opposite.

The original text is in the document of Tomcat:

Http://localhost/tomcat-docs/config/printer/http.html But this document is a problem, he said that uriencoding is encoded by ISO-8859-1 by default, is not the case. There is a conclusion that the cattle study Tomcat source code. Example:

Debug = "0"

Acceptcount = "100"

ConnectionTIMEOUT = "20000"

DisableUploadTimeout = "True"

Port = "80" redirectport = "8443"

Enablelookups = "false"

MinSparethreads = "25"

Maxsparethreads = "75"

Maxthreads = "150"

Maxpostsize = "0"

Uriencoding = "ISO-8859-1">

Quote:

http://www.javaworld.com.tw/jute/post/view?bid=9&age=44042&sty=3&age=0&tpg=1&pg=1

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

New Post(0)