When using GET request to download the file, because the address bar uses the ISO-8859-1 code format to produce garbled, gets incorrect value __ the code

Source: Internet
Author: User

First, for example, when the request URL is like this, the front domain port is omitted, .../test/downloadservlet/filepaht=f:/hello world. rmvb

Hello world. These strings will cause garbled problems because of the iso-8859-1 encoding of the address disorder.

The method is to encode the request parameter value after obtaining the request parameter, that is, converting it to a byte array, and then decoding the byte array back into a string.
String str=request.getparameter ("name");
Byte[] Bytes=str.getbytes ("iso-8859-1");
String name=new string (bytes, "Utf-8");
This will be able to get the right path, the implementation of the file download.


There is another way, in other people's place, I have not tried, we can try ...

String str=request.getquerystring ();
Decoding strings using Urldecoder
String Str1=java.net.urldecoder.decode (str, "utf-8");
String[] Parastrings=str1.split ("&");
Parastrings[0] is the first argument, and so on ...
for (String parastring:parastrings)
{
String[] Namevalue=parastring.split ("=");
Namevalue[0] is the form's name,namevalue[1] is the value of the form name
}

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.