html page in two ways specified character set

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

  method one:

<meta charset="utf-8">

  Second way:

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

  These are the pages of the character set to UTF-8 in two ways (settings page character set), aims: to tell the browser character set of the html file.

2. Set pages use the character set in two ways

The first: the server response specifies the character set of the contents;

response.setCharacterEncoding("utf-8")

Premise: server through the server, or redirected to the specified interface.  

The second: page specified character set.

See 1

Description: The first way is a priority higher than the second.

3. Server forwards

  Page has been set up character sets

  This is how it is, why not take effect? 

2. Analysis

  Jump through the server to complete page request (forward)

  When returned, and did not specify the character set to be returned data. 

  F12 capture the appropriate page of the network, acquired the character set is iso-8859-1, so there will be garbled when parsing the page browser.     

3. Solution

  If you are forwarding, you need to specify the character set to return data to utf-8 can be.

response.setCharacterEncoding("utf-8");

4. The server redirects

  Redirection, and the data returned is not specified code set, the page will happen? 

  Character Set page final say, namely: the page character set page statement on the character set of decisions.

  For example: page specified character set is: iso-8859-1

  The browser will be resolved in accordance with iso-8859-1. 

  In addition, even if the redirection settings return data encoding set, also invalid because: redirect will result in data loss!

5. Summary

  If the page is forwarded from the server, the page character set by the forwarding decisions; otherwise, the redirection of interface or common interface is determined by the character set of HTML pages character set declaration itself!

  Note: Today, talking about the problem page character set and pure data exchange not the same thing!

  In addition, if the HTTP response header and the meta specifies the character set, it can cause conflict, character set http response effect.

 

 

Written in the last

  Which big brother If it is found there is leakage of the carelessness of the article or need to add more content, welcome message! ! !

 related suggestion:

 

Guess you like

Origin www.cnblogs.com/Marydon20170307/p/11481780.html