If the parameter value is in Chinese when the request parameter is obtained through the requests object, the obtained parameter will be garbled if it is not processed. In JSP, to solve the request parameters are the Chinese garbled situation, can be divided into the following two kinds:
1. Get access Request parameter garbled
When the access request parameter is Chinese, the Chinese parameter value obtained through the object is garbled because the request parameter is ISO-8859-1 encoded and does not support Chinese. Therefore, you can display Chinese correctly only if you reconstruct a string object using the UTF-8 or GBK encoding of the acquired data through string construction. For example, when you get the parameter user that includes Chinese information, you can use the following code:
<span style= "FONT-SIZE:18PX;" >string user=new String (request.getparameter ("user"). GetBytes ("Iso-8859-1"), "Utf-8");</span>
2. Get the information of the form submission garbled
The Chinese parameter value obtained through the request object is garbled when the form's information is obtained. This can be done by setting the encoding to UTF-8 or GBK by adding the setcharacterencoding () method that invokes the request object under the page directive. For example, when you get the value of a user name text box that includes Chinese information (the Name property is username), you can add the following code before you get all the form information:
<span style= "FONT-SIZE:18PX;" ><%
request.setcharacterencoding ("UTF-8");
%></span>
In this way, the following code to get the value of the form, it will not produce Chinese garbled.
<span style= "FONT-SIZE:18PX;" >string user =request.getparameter ("username");</span>