Home >Web Front-end >HTML Tutorial >html Chinese garbled HTML hyperlink Chinese garbled problem analysis and solutions_HTML/Xhtml_Web page production

html Chinese garbled HTML hyperlink Chinese garbled problem analysis and solutions_HTML/Xhtml_Web page production

WBOY
WBOYOriginal
2016-05-16 16:40:412627browse

A hyperlink URL in Vm needs to be spliced ​​into Chinese as a parameter of the Get request. If spliced ​​directly, it will be garbled after being passed to the parameter object of the background Action and taken out. It needs to be encoded and then spliced ​​to the URL.
The solution is to add a member variable in Action to save the encoded Chinese parameters. When rendering the vm page, take out the value of this variable and then splice the hyperlink.

The problem encountered here is : when calling the encode() method of java.net.URLEncoder, if the specified character set parameter is not displayed, then URLEncoder will use the default character set. This default character set will produce different results when running the main() method in Eclipse and running the Web application in Tomcat, thus affecting the encoding results.

Copy code
The code is as follows:

/**
* Translates a string into x-www-form-urlencoded
* format. This method uses the platform'sdefault encoding
* as the encoding scheme to obtain thebytes for unsafe characters.
*
* @param s String to betranslated.
* @deprecated The resulting string mayvary depending on the platform's
* default encoding. Instead, use theencode(String,String)
* method to specify the encoding.
* @return the translated String.
*/
@Deprecated
public static String encode(String s) {
String str = null;
try {
str = encode(s, dfltEncName);
} catch(UnsupportedEncodingException e) {
// The system should always have the platform default
}
return str;
} The comment of the

method also states that the reason why it is not recommended is, This encode(String) method depends on the platform character set.
Statement:
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