We often use the following method for parameter passing, for example:
View plaincopy to clipboardprint?
- <A href = "....? Action = Chinese parameter "mce_href = "....? Action = Chinese parameter "> URL parameter transfer </a>
<A href = "....? Action = Chinese parameter "mce_href = "....? Action = Chinese parameter "> URL parameter transfer </a>
The background only has the following code:
View plaincopy to clipboardprint?
- String action = request. getparameter ("action ");
String action = request. getparameter ("action ");
The obtained information may be garbled. Common solutions include:
1.
View plaincopy to clipboardprint?
- Request. setcharacterencoding ("UTF-8 ");
- String action = new string (request. getparameter ("action "));
Request. setcharacterencoding ("UTF-8"); string action = new string (request. getparameter ("action "));
2.
View plaincopy to clipboardprint?
- String action = new stirng (request. getparameter (Action). getbytes ("UTF-8 "));
String action = new stirng (request. getparameter (Action). getbytes ("UTF-8 "));
3.
Some also say modifying the configuration file in server. XML in Tomcat, adding uriencoding = "UTF-8"
View plaincopy to clipboardprint?
- <Connector Port = "8080" protocol = "HTTP/1.1"
- Connectiontimeout = "20000"
- Redirectport = "8443" usebodyencodingforuri = "true" uriencoding = "UTF-8"/>
<Connector Port = "8080" protocol = "HTTP/1.1" connectiontimeout = "20000" redirectport = "8443" usebodyencodingforuri = "true" uriencoding = "UTF-8"/>
The above methods can all pass (not ie6.0), but if you test in ie6.0, there are many problems.
Test in ie6.0 found that ie6.0 has a limit on the length of Chinese parameters. When more than two Chinese characters are entered, the third character will generate Chinese garbled characters and cannot obtain all the parameter values, this may be a bug in ie6.0. The solution is provided below.
The following code encrypts Chinese characters when passing parameters:
Foreground URL:
View plaincopy to clipboardprint?
- <A href = "......? Action = <% = java.net. urlencoder. encode ("mce_href = "......? Action = & lt; % = java.net. urlencoder. encode ("Chinese Parameters", "UTF-8") %> "> URL parameter transfer </a>
<A href = "......? Action = <% = java.net. urlencoder. encode ("mce_href = "......? Action = & lt; % = java.net. urlencoder. encode ("Chinese Parameters", "UTF-8") %> "> URL parameter transfer </a>
Code accepted in the background:
View plaincopy to clipboardprint?
- String action = new string (request. getparameter (). getbytes ("UTF-8 "));
String action = new string (request. getparameter (). getbytes ("UTF-8 "));
The test passed in ie6.0 without garbled characters and encrypted Chinese characters, for example, % E8 % AE % B8 % E7 % 8e % B2, which improves security.