Uri parameter Chinese garbled characters (for IE6)

Source: Internet
Author: User

We often use the following method for parameter passing, for example:

View plaincopy to clipboardprint?

  1. <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?

  1. String action = request. getparameter ("action ");

String action = request. getparameter ("action ");

 

The obtained information may be garbled. Common solutions include:

 

1.

View plaincopy to clipboardprint?

  1. Request. setcharacterencoding ("UTF-8 ");
  2. String action = new string (request. getparameter ("action "));

Request. setcharacterencoding ("UTF-8"); string action = new string (request. getparameter ("action "));

 

2.

View plaincopy to clipboardprint?

  1. 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?

  1. <Connector Port = "8080" protocol = "HTTP/1.1"
  2. Connectiontimeout = "20000"
  3. 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?

  1. <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?

  1. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.