<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