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
Regular expressions are often used to search and ...
Just add the following code to achieve it. Method ...
The large-screen digital scrolling effect comes f...
Preface This article mainly introduces the releva...
Recommended reading: Navicat12.1 series cracking ...
Table of contents 1. Concept 1.1 Definition 1.2 D...
This article mainly explains tables, which are no...
1. Clear floating method 1 Set the height of the ...
mysql storage engine: The MySQL server adopts a m...
Compared with ordinary programs, dynamic link lib...
1. Big Data and Hadoop To study and learn about b...
This article mainly introduces how to specify par...
MySQL temporary tables are very useful when we ne...
1: Install mongodb in docker Step 1: Install mong...
1. Introduction to mysqldump mysqldump is a logic...