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
Table of contents 1. Introduction 2. Back up the ...
background First, let me explain the background. ...
As shown in the following figure: If the version ...
This article example shares the specific code of ...
1. Command Introduction The file command is used ...
This article shares the specific code for React t...
Why can it set the height, but unlike elements lik...
Before reading this article, I hope you have a ba...
Since its launch in 2009, flex has been supported...
Table of contents Preface Why How much is it? Num...
1. Solution to the problem that the page is blank...
This article example shares the specific code of ...
introduction Have you ever encountered a situatio...
1. Permanent modification, valid for all users # ...
Rendering Code - Take the blue and yellow rings a...