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

CSS3 realizes draggable Rubik's Cube 3D effect

Mainly used knowledge points: •css3 3d transforma...

vue3.0+echarts realizes three-dimensional column chart

Preface: Vue3.0 implements echarts three-dimensio...

React native realizes the monitoring gesture up and down pull effect

React native implements the monitoring gesture to...

Vue uses el-table to dynamically merge columns and rows

This article example shares the specific code of ...

A brief description of the relationship between k8s and Docker

Recently, the project uses kubernetes (hereinafte...

CSS3 achieves various border effects

Translucent border Result: Implementation code: &...

How to create, start, and stop a Docker container

1. A container is an independently running applic...

MySQL slow query: Enable slow query

1. What is the use of slow query? It can record a...

Javascript design pattern prototype mode details

Table of contents 1. Prototype mode Example 1 Exa...

Vue-pdf implements online preview of PDF files

Preface In most projects, you will encounter onli...

Design Reference Beautiful and Original Blog Design

All blogs listed below are original and uniquely ...

Implementing image fragmentation loading function based on HTML code

Today we will implement a fragmented image loadin...

How to enable the root account in Ubuntu 20.04

After Ubuntu 20.04 is installed, there is no root...

MySQL 5.7.12 installation and configuration tutorial under Mac OS 10.11

How to install and configure MySQL on Mac OS 10.1...