Javascript uses the address bar to pass values to actions (Chinese garbled characters are full of question marks) _ javascript skills

Source: Internet
Author: User
I passed a value from the address bar in the js Code to the corresponding variable of the action. However, if the variable value is Chinese, in the test output in the action, the question mark is a small problem encountered when the project of an ssh framework was completed a few days ago. This is the case.
The private variable is defined in the action and the get () and set () methods are provided, which should be accessible in js Code. Therefore, I passed a value from the address bar in the js Code to the corresponding variable of the action. However, if the variable value is Chinese, the test output in the action is "?", Chinese characters are still displayed in the address bar of the browser.

I first configured the tomcat configuration file according to some answers on the Internet. Later I thought it might not be a complicated issue, but it should be the encoding issue. Both my myeclipse and project code are set to "UTF-8 ". So I tried to set both the project and myeclipse code to "iso8859-1", or not.

This is not the case, so I took a more direct approach. In the action, convert the obtained variable value (assuming the variable is string ):

The Code is as follows:


String newstring = new String (string. getBytes ("iso8859-1 "));


However, this is useless ~~~~~~ I tried it for a long time and found that my idea is correct, but the appropriate statement should be as follows:

The Code is as follows:


String newstring = new String (string. getBytes ("iso8859-1"), "UTF-8 ");


Ps: I first try to convert it into GBK, and then I find that the word can be displayed, but no one knows it... Sure enough, the support of "iso8859-1" for Chinese is good.

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.