Home > Web Front-end > JS Tutorial > js transfers value to action through the address bar (Chinese garbled characters are all question marks)_javascript skills

js transfers value to action through the address bar (Chinese garbled characters are all question marks)_javascript skills

WBOY
Release: 2016-05-16 17:34:48
Original
1064 people have browsed it

A few days ago, I encountered a small problem while completing an ssh framework project. The situation is like this.
Private variables are defined in the action and provide get() and set() methods, which should be accessible in js code. So I passed the value from the js code to the corresponding variable of the action through the address bar. However, if the variable value is Chinese, the test output in the action is "???", but it can still be displayed in the browser address bar. Chinese.

I first configured the tomcat configuration file based on some answers online, but to no avail. Later, I thought about it, maybe it wasn't a complicated problem, it was probably an encoding problem. The encoding of my myeclipse and project are both set to "UTF-8". So I tried to set both the project and myeclipse encoding to "iso8859-1", but it still didn't work.

This didn’t work, so I took a more direct approach and tried converting the obtained variable value in the action (assuming the variable is a string):

Copy code The code is as follows:

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

But this still doesn’t work~~~~~~After trying for a long time, I found that my idea is right, but the appropriate statement should be as follows:
Copy code The code is as follows:

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

ps: I first tried to convert to GBK, and then found that the characters could be displayed, but no one knew the characters. . . Sure enough, "iso8859-1" supports Chinese better
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template