Three JSP compilation commands

Source: Internet
Author: User

The JSP compilation command notifies the JSP engine of the message and does not generate the output directly. Compiling commands have default values, so developers do not need to assign values to each command. Its basic syntax is: <% @ compile command Name property name = "property value" · %>

(1) page: this command is for the current page. The page command is usually at the top of the JSP page. Multiple page commands can be used on a JSP page. Syntax format of the page command:

<%@ Page
[Language = "Java"]
[Extends = "package. Class"]
[Import = "package. classipackage .*},... "]
[Session = T rueifalse "]
[Buffer = "nonei8kbisize kb" 1
[Autoflush = "trueifalse"]
[Isthread8afe = "trueifalse"] [info = "text"]
[Errorpage = "relativeurl"]
[Contenttype = mimetype [; charset = character8et] "I" text/html; char8et = job 808859-1 "]
[Iserrorpage = "trueifalse"]
%> 〉


The following describes the attributes of a page in sequence.

Language: Declares the type of script language used for the current JSP page. Because the page is a JSP page

The attribute values are generally Java.

Extends: determines the Java class generated during JSP program compilation, the parent class to be inherited, or the fully qualified class name of the interface to be implemented.

Import: used to import packages. The following packages are automatically imported by default and do not need to be explicitly imported. Default imported packages include:

Java. Lang. * javax. servlet. * javax. serlet. jsp. * javax. servlet. Http *

Session: sets whether htip session is required for this JSP page.

Buffer: specify the size of the output buffer. The internal JSP object of the output buffer: Out is used to cache the output of the JSP page to the client browser. The default value is octal. It can be set to none or 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 is normal. If it is set to false, an exception occurs during Buffer Overflow.

Info: Set the information of the JSP program, which can also be seen as its description. You can obtain the value through the serlet. getservletinfoo method. If you are on a JSP page, you can directly call the getservletinfoo method to obtain this value, because the JSP page is essentially serlet.

E * orpage: Specifies the error handling page. If an exception or error occurs in this program and the JSP page does not have the corresponding processing code, the JSP page specified by this instruction is automatically called. When Using JSP pages, you can ignore exceptions, even if they are checked exceptions.

Iserroepage: sets whether the JSP page is an error handler. If the page itself is an error handling page, you do not need to use the errorpage attribute.

Contenttype: used to set the file format and encoding method for generating web pages, that is, MIME type and page Yu character set type, the default MIME type is textlhtml; default character set is ISO-8859-1


The errorpage attribute is essentially a JSP Exception Handling Mechanism. jsp scripts do not require forced Exception Handling, even if the exception is a checked exception. If an unhandled exception is thrown during the running of the JSP page, the system automatically jumps to the page specified by the errorpage attribute. Once the errorpage attribute sets the specified JSP page, the iserrorpage attribute of the specified JSP page is set to true.

(2) include command: Used to include another page. You can embed an external file into the current JSP file and parse the JSP statement on this page. This is a static include statement that includes other compilation commands on the target page, but does not dynamically. Include can contain both static text and dynamic JSP pages.

Syntax: The <% @ include file = "relativeurlspec" %> include command should preferably contain static content that does not need to be changed frequently. If the embedded file needs to change frequently, we recommend that you use the <JSP: Include> Operation Command.


(3) taglib commands

The taglib command allows the page to use custom tags. You must first develop your own tag Library (taglib), write a configuration file (File suffixed with. TLD) for the tag library, and then use the custom tag on the JSP page. The tag is used to increase the degree of code reuse. For example, you can make some content that requires iterative display into a tag, which is used every time you need iterative display. Using tags also makes the page easy to maintain.

In the JSP specification, the tag library has been continuously strengthened, and the JSP standard tag Library (jstl) has been added to the latest JSP 2.0 specification, which can be directly applied by users.

The syntax format of using the custom tag library or jstl in JSP is as follows.

<%@ taglib uri="tablibURI" prefix="tagPrefix"%>

Uri indicates the address of the tag library, that is, how to find the tag description file and tag library for the JSP Container. prefix indicates that the tag prefix is referenced on the JSP page, these prefixes cannot be JSP, jspx, Java, javax, sun, Servlet, or sunw.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.