Get method Chinese garbled problem

Source: Internet
Author: User

<a target= "_blank" href= "ftpfileaction!downloadfile.action?filename= test. xml" > Click to download </a>

If the current page encoding is utf-8.

This is main.jsp.

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>

and head heads.

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">

and the file encoding of main.jsp itself is utf-8.

In the case of post, the servlet background setting request.setcharacterencoding (' Utf-8 ') must be correct in Chinese.

For Get methods, however, if the Get method submits a parameter that contains Chinese,

In my native test, ie submitted under the use of iso-8859-1 transcoding GBK can get normal Chinese.

Filename=new String (filename.getbytes ("iso-8859-1"), "GBK");

The parameters submitted under Firefox use the Iso-8859-1 transcoding utf-8 in the servlet to get normal Chinese.

Filename=new String (filename.getbytes ("iso-8859-1"), "Utf-8");

The reason to transcode is that Tomcat does not transcode using request.setcharacterencoding encoding, but instead uses iso-8859-1 for parameters that are submitted in get mode.

To ensure the compatibility of each browser,

Parameters can be transcoded when the parameter is submitted in get mode.

encodeURI (suitable for encoding the entire URI) and encodeURIComponent (part of the parameters that are appropriate for encoding the URI)

JS script:

Filename=encodeuricomponent (' Test. xml ');

' <a target= ' _blank "href=" ftpfileaction!downloadfile.action?filename= ' +filename+ ' "> Click to download </a> '

Indicate:

encodeURI, encodeURIComponent is UTF-8.
Escape is Unicode.

Escape does not encode characters with 69: *,+,-,.,/,@,_,0-9,a-z,a-z

encodeURI does not encode 82 characters:!,#,$,&, ', (,), *,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,a-z

encodeURIComponent does not encode 71 characters:!, ', (,), *,-,.,_,~,0-9,a-z,a-z

Get method Chinese garbled problem

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.