Page JSP page directive specifies the encoding and Meta tag coding

 1 JSP代码如下:
 2 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 3 pageEncoding="ISO-8859-1"%>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 8 <title>Insert title here</title>
 9 </head>
10 <body>
11 </html>

In it encoded with the type of place there at 3:

1, jsp contentType attribute of the page directive

contentType = "text / html; charset = ISO-8859-1"
This code specifies the coded output html page. That is output by the Servlet returns to the browser display page

2, jsp attribute of the page directive pageEncoding

pageEncoding = "ISO-8859-1"
This code specifies the encoding type of a JSP page is saved as a character encoding type .jsp file will be converted through the container file is saved, which is first converted to the corresponding .java java source files (corresponding to the servlet succession) this process is in accordance with the specified coding pageEncoding read. .Java files and converted to UTF-8 coding .class files are compiled after a predetermined back.

Note that if you do not specify the encoding format here, it may not be correctly converted to .java file, where there are different from the java file jsp, jsp file to java file conversion mode no default encoding is not specified would not be able to resolve correctly, and java file to convert class files have default encoding format, native encoding format, which means that by default javac compiler tool parses java file encoding format according to the computer system, which is why the system comes with Notepad to write code editor the reason can be correctly compiled.

3、html中的<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<meta http-equiv = "Content -Type" content = "text / html; charset = ISO-8859-1">
here encoding charset = ISO = 8859-1 is to tell the browser, I returned to your HTML page coding What format is that this browser can correct encoding format to parse the HTML page.

to sum up:

The encoding type 1 and 3 must be consistent, and the second type does not matter, the appropriate encoding format may be selected according to their character types contained in the page.

Further, the source code may be provided java encoding format, transcoding operations can be done.

Guess you like

Origin www.cnblogs.com/lijie0609/p/12009233.html