Analysis and solution of Chinese garbled characters in HTML hyperlinks

Analysis and solution of Chinese garbled characters in HTML hyperlinks
A hyperlink URL in Vm needs to be concatenated with Chinese as a parameter of the Get request. If you splice directly, the parameter object passed to the background Action will be garbled when retrieved, and needs to be encoded before splicing into the URL.
The solution is to add a member variable in Action to save the encoded Chinese parameters. When the vm page is rendered, take out the variable value and then splice the hyperlink.

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

Copy code
The code is as follows:

/**
* Translates a string into <code>x-www-form-urlencoded</code>
* format. This method uses the platform's default encoding
* as the encoding scheme to obtain the bytes for unsafe characters.
*
* @param s <code>String</code> to be translated.
* @deprecated The resulting string may vary depending on the platform's
* default encoding. Instead, use theencode(String,String)
* method to specify the encoding.
* @return the translated <code>String</code>.
*/
@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 method's comments also state that the reason it is not recommended is that the encode(String) method depends on the platform character set.

<<:  Theory Popularization——User Experience

>>:  Explore VMware ESXI CLI common commands

Recommend

MySQL uses custom functions to recursively query parent ID or child ID

background: In MySQL, if there is a limited level...

Vue.js $refs usage case explanation

Despite props and events, sometimes you still nee...

MySQL 8.0.15 installation tutorial for Windows 64-bit

First go to the official website to download and ...

The easiest way to make a program run automatically at startup in Linux

I collected a lot of them, but all ended in failu...

Installation of Docker CE on Ubuntu

This article is used to record the installation o...

How to get the size of a Linux system directory using the du command

Anyone who has used the Linux system should know ...

The pitfall record of case when judging NULL value in MySQL

Table of contents Preface Mysql case when syntax:...

CSS multi-level menu implementation code

This is a pretty cool feature that makes web page...

CSS Paint API: A CSS-like Drawing Board

1. Use Canvas images as CSS background images The...

The principle and basic use of Vue.use() in Vue

Table of contents Preface 1. Understanding with e...

Docker implements container port binding local port

Today, I encountered a small problem that after s...

Sequence implementation method based on MySQL

The team replaced the new frame. All new business...

CSS uses calc() to obtain the current visible screen height

First, let's take a look at the relative leng...

Docker image creation Dockerfile and commit operations

Build the image There are two main ways to build ...