Usually coding, often encountered some garbled problems, and now summarize the use of servlets encountered some garbled problems, simple solution two
The first simple way to handle
Data processing in Servlets is handled through request and response, and there are two ways to submit data: Post+get
①post Submission Method-As long as request.setcharacterencoding ("UTF-8") is set beforehand;-------Note: only valid for POS submission
②get Submission Method-by iso8859-1 the data sent by the client, and then into the UTF-8 type. (or other type, gbk,gb2312)
String username = Request.getparameter ("username"), username = new String (username.getbytes ("Iso8859-1", "UTF-8"));
From the above two methods can be seen if it is a get submission method, to do the processing is quite cumbersome, so in the submission mode setting, we recommend that you use post, which is one of the benefits of post. But there is also a hyperlink from the client submitted by the Chinese processing, the server can only get processing.
In response to the server, through the response response, for Chinese garbled problem, also must be processed.
through Response.setcharacterencoding ("UTF-8"); Response output in a "UTF-8" manner
Response.setcontenttype ("Text/html;charset=utf-8"); And tell the browser to open it in "UTF-8" mode.
The second filter way to deal with garbled problem, the principle and code follow up ~
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Handling Chinese garbled problems in Servlets