Chinese parameters passed to the action in JS are garbled

Source: Internet
Author: User

See: http://topic.csdn.net/u/20080602/11/0edf10dd-8b67-4d3e-ad9d-ff022d397e0b.html

Encode the Chinese characters in JS first...
Then decode the code in action...
Specific implementation...
JS Code
VaR comment = Document. All. Comment. value;
Comment = encodeuri (comment );
Comment = encodeuri (comment); // note twice

Action Decoding
String comment = request. getparameter ("comment ");
Try {
Comment = java.net. urldecoder. Decode (comment, "UTF-8 ");
} Catch (unsupportedencodingexception e ){
E. printstacktrace ();
}
Trace the variable value from the program and find the correct Chinese characters in the action, but the final query result is still a blank set. Execute sqlquery in the database to find that the query result is null, you have to set an encoding attribute of the original database, that is, change collation of sqlserver to chinese_prc_cs_ai.

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.