Two ways to specify the character set of the html page

Two ways to specify the character set of the html page

1. Two ways to specify the character set of the html page

Method 1:

<meta charset="utf-8">

Method 2:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

The above are two ways to set the character set of the page to UTF-8 (setting the page character set). The purpose is to tell the browser the character set of the HTML file.

2. Two ways to set the character set used by the page

The first one: the server specifies the character set of the response content;

response.setCharacterEncoding("utf-8")

Prerequisite: The server forwards or redirects to the specified interface through the server.

The second type: page specifies the character set.

See 1

Note: The first method has a higher priority than the second method.

3. Server forwarding

The page has already set the character set

What's going on and why isn't it working?

Cause Analysis

Complete the page jump request (forwarding) through the server

When returning, the character set of the data to be returned is not specified.

f12 captures the network and obtains the character set of the corresponding page as iso-8859-1, so garbled characters will appear when the browser parses the page.

Solution

If it is forwarding, you need to specify the character set of the returned data as utf-8.

response.setCharacterEncoding("utf-8");

Server Redirection

What happens to the page if you redirect without specifying the encoding set of the returned data?

The character set is determined by the page, that is, the character set of the page is determined by the declaration of the character set in the page.

For example: the page specifies the character set: iso-8859-1

The browser will also parse it according to iso-8859-1.

In addition, even if the redirection setting returns the encoding set of the data, it will be invalid because: redirection will cause data loss!

5. Summary

If the page is forwarded by the server, the character set of the page is determined by the forwarding; otherwise, the character set of the redirected interface or the normal interface is determined by the character set declared in the HTML page itself!

Note: What we are talking about today is the problem of page character set, which is not the same as the garbled characters that appear during pure data interaction!

In addition, if the character set is specified in both the HTTP response header and the meta, a conflict will occur and the character set of the http response will take effect.

The above are the details of the two methods of specifying the page character set in HTML. For more information about specifying the page character set in HTML, please pay attention to other related articles on 123WORDPRESS.COM!

<<:  Detailed explanation of CSS background and border tag examples

>>:  What magical uses does CSS filter have

Recommend

How to use regular expression query in MySql

Regular expressions are often used to search and ...

Let the web page redirect to other pages after opening for a few seconds

Just add the following code to achieve it. Method ...

You may need a large-screen digital scrolling effect like this

The large-screen digital scrolling effect comes f...

Detailed explanation of MySQL custom functions and stored procedures

Preface This article mainly introduces the releva...

Navicat for MySQL 11 Registration Code\Activation Code Summary

Recommended reading: Navicat12.1 series cracking ...

TypeScript decorator definition

Table of contents 1. Concept 1.1 Definition 1.2 D...

Bootstrap3.0 study notes table related

This article mainly explains tables, which are no...

Two ways to clear float in HTML

1. Clear floating method 1 Set the height of the ...

How to modify the default storage engine in MySQL

mysql storage engine: The MySQL server adopts a m...

Use of Linux dynamic link library

Compared with ordinary programs, dynamic link lib...

How to use VirtualBox to build a local virtual machine environment on Mac

1. Big Data and Hadoop To study and learn about b...

How to specify parameter variables externally in docker

This article mainly introduces how to specify par...

Simple usage of MySQL temporary tables

MySQL temporary tables are very useful when we ne...

Detailed steps to install Docker mongoDB 4.2.1 and collect springboot logs

1: Install mongodb in docker Step 1: Install mong...

How to use mysqldump to backup MySQL data

1. Introduction to mysqldump mysqldump is a logic...