JSP compilation instructionsIs a message that notifies the JSP engine. It does not generate output directly. Compiling commands have default values, so developers do not need to set values for each command.
The following are common compilation commands:
① Page: This command is for the current page.
② Include: Used to specify to include another page.
③ Taglib: Used to define and access custom tags.
The syntax format of the compiled command is as follows:
<% @ Compile command Name property name = "property value"... %>
Page command:
The page command is usually at the top of the JSP page. Multiple page commands can be used on a JSP page. The following describes the meaning of the attributes of the page command:
Language: Declare the types of script languages used on the current JSP page. Currently, the value of this attribute can only be Java, and the default value is Java, so you do not need to set it.
Import: Used to import packages. The following packages are automatically imported by default. The default packages are: Java. lang. *, javax. servlet. *, javax. servlet. HTTP. *, javax ,. servlet. JSP. *.
Contenttype: Informs the client of the body format (MIME type) and encoding Character Set of the response sent from the server to the request. The default MIME type is text/html, the default character set is ISO-8859-1, domestic development generally sets the character set to UTF-8 or GBK. So this is common: contenttype = "text/html; charset = UTF-8", that is, to tell the client that the server's response body file is in the format of text/html, in this way, the client will choose to open the file with its own default browser, rather than other applications.Charset = UTF-8Inform the client browser that the encoding format of the file returned by the server is UTF-8, so that the browser decodes according to the UTF-8 format and displays the page in the UTF-8 character set. The role of contenttype is essentially equivalent to simulating an HTTP message header. Although contenttype is written in a JSP file, the JSP file does not directly respond to the client request. It must be compiled into the corresponding servlet before it can respond to the request. Therefore, in essence, this contenttype is for servlet settings, that is, the servlet tells the client that the file I returned (in the form of a stream, response. the MIME type of getwriter () is text/html, And the encoding Character Set of the file is UTF-8.
Pageencoding: Set the encoding used for saving the JSP source file (right-click the file in myeclipse-> properties-> resource-> text file encoding. Which character set is used for the value of myeclipse and pageencoding, this character set is automatically used for saving ). To respond to client requests, JSP files must first be compiled into a servlet, while servlet is a Java class, and Java classes are encoded in Unicode in the memory, if the JSP Engine (Translating JSP into the corresponding servlet) does not know the JSP encoding format, it cannot be decoded and then converted to the Unicode encoding in the memory. Note that the charset and pageencoding of contenttype are differentiated,CharsetWhen the response is received, Servlet (JSP has been compiled into servlet) tells the client browser that "I" is encoded with this character, and "you" should also be decoded and displayed with this character, the whole process involves two aspects: server and client.PageencodingThe JSP file on the server tells the JSP Engine what encoding to decode. That is, JSP has not yet been compiled into a servlet. It is a prerequisite for compiling it into a servlet, the whole process occurs on the server and has nothing to do with the client.
Session: Sets whether the JSP page supports the session mechanism. The default value is true. Therefore, you do not need to set the default value.
Errorpage: Specifies the address of the error handling page. If an exception or error occurs on this page and the JSP page does not have the corresponding processing code, the JSP page pointed to by this attribute is automatically called.
Iserrorpage: Used with the errorpage attribute. Set whether the current JSP page is an error handling page.
Info: Set the information of the JSP program (do not forget that it is essentially a servlet), it can also be seen as its description. You can use servlet. getservletinfo () to obtain the value. On the JSP page, you can directly call the getservletinfo () method to obtain the value, for example, <% = getservletinfo () %>. because JSP is a servlet, and any servlet implements the servlet interface, the servlet Interface contains the getservletinfo () method. Do you still remember the five methods in the servlet interface of Daming Lake!
Extends: Specifies the parent class or implemented interface inherited by the servlet generated by JSP compilation, which is rarely used.
Buffer: Specify the size of the output buffer. JSP's hidden object out (JSP has nine hidden objects or built-in objects) used to cache JSP (actually servlet) output to the client browser. The default value is 8 KB and can be set to none, you can also set it to another value, in KB.
Autoflush: Whether to force the output buffer content when the output buffer is about to overflow. If it is set to true, the output can be normal. If it is set to false, an exception occurs during Buffer Overflow.
The most common attributes above are import, contenttype, and pageencoding. Therefore, the most common and simple JSP template is:
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>