Garbled characters in program development and Solutions

Source: Internet
Author: User

 

Garbled characters occur in program development:

1: Use JS functions as URL parameterized jump, such as window. open (URL). At this time, the URL is a URL with parameters spliced, including characters other than ASCII, then an error occurs when receiving the page, this part of Non-ASCII encoding is garbled.

2: Use the server-side jump method, such as respon. Redirect to jump to a URL with parameters. In this case, problems may also occur due to browser compatibility issues.

 

Solution of Case 1:

1: In the default web. config file, <globalization requestencoding = "UTF-8" responseencoding = "UTF-8"/>

Modify the default format to <globalization fileencoding = "gb2312" requestencoding = "gb2312" responseencoding = "gb2312"/> to solve the problem.

2: encode the parameterized URL transmitted by JS

For example:

Function jumptopage (){
VaR url = encodeuri ("Accept encoding page (get passed parameters). aspx ");
VaR paramspart = encodeuri ("? Name = Haha & adddress = People's Republic of China ")
// Var paramspart = "? Name = "+ escape ('Ha) +" & adddress = "+ escape ('People's Republic of China') + "";
VaR totolurl = URL + paramspart;
Window. Location. href = totolurl;
}

Function jumptopageescape (){
VaR url = "reciveparamspage. aspx ";
VaR paramspart = "? Name = "+ escape ('Ha) +" & adddress = "+ escape ('People's Republic of China') + "";
VaR totolurl = URL + paramspart;
Window. Location. href = totolurl;
}

VaR url = "A. aspx? Cd = "+ hotelcd +" & name = "+ escape (name) + "";

Accept page, normal acceptance or server. urldecode (request. querystring ["name"]. tostring.

 

Solution for Case 2:

Before the response. Redirect jump, call server. urlencode to encode the URL, and use server. urldecode to decode the URL on the acceptance page.

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.