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
docker-compose-monitor.yml version: '2' n...
1: Tag selector The tag selector is used for all ...
The Docker images we usually build are usually la...
Table of contents Install: 1. Basic use of firewa...
Is it the effect below? If so, please continue re...
1. First look at the request configuration file, ...
Table of contents 1. What is lazy loading? 2. Imp...
Pseudo-arrays and arrays In JavaScript, except fo...
Table of contents 1. this keyword 2. Custom attri...
Being an operation and maintenance engineer is a ...
<br />This tag can display a horizontal line...
Let’s take the translation program as an example....
This article shares the specific code of writing ...
This article example shares the specific code of ...
In this article, I will show you how to install a...