Chinese garbled characters transmitted by JS and JSP

Source: Internet
Author: User
Address: Http://hi.baidu.com/comasp/blog/item/e13e928b4eeb59d2fc1f10d8.html

I encountered this exception when passing parameters through Ajax. After finding something online for N days, I still did not find the answer. It turns out that I have not found any errors caused by escape. I wrote it like this.

VaR url = "B. jsp? Name = "+ escape (u_name );

Server get:

String name = request. getparameter ("name ");
Name = new string (name. getbytes ("iso-8859-1 "));
System. Out. println (name );

The following error is reported: org. Apache. tomcat. util. http. Parameters processparameters.
Warning parameters:Character Decoding Failed.Parameter Skipped.
Java. Io. charconversionexception: ishexdigit.

I know it's a String Conversion exception, but I don't know how to fix it.

Later I heard that it was an escapse problem, so I began to look for information. Finally solved the problem.

Change the URL first:

VaR url = "B. jsp? Name = "+ u_name;
Url = encodeuri (URL );
Url = encodeuri (URL); // You cannot write one. If you write one, it is ???? .
// Write two, and output % DF % A4.

Server get:

string name = request. getparameter ("name");
name = java.net. urldecoder. decode (name, "UTF-8"); // This sentence must be, because if not written //, the encoding is % E5 % a6 % 88% system. out. println (name);

Related Article

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.