JSP Syntax (7)

Source: Internet
Author: User
Tags character set include client
js| syntax
Page directives

Defines global properties in a JSP file.



JSP syntax

<%@ page

[language= "Java"]

[extends= "Package.class"]

[import= "{package.class | package.*}, ..."]

[Session= ' true | false ']

[buffer= "none | 8kb | sizekb"]

[Autoflush= ' true | false ']

[Isthreadsafe= ' true | false ']

[info= "Text"]

[errorpage= "Relativeurl"]

[contenttype= "mimetype [; Charset=characterset]" | "Text/html; Charset=iso-8859-1 "]

[Iserrorpage= ' true | false ']

%>

Example

<%@ page import= "java.util.*, java.lang.*"%>

<%@ page buffer= "5kb" autoflush= "false"%>

<%@ page errorpage= "error.jsp"%>

Describe

The <%@ page%> instruction acts on the entire JSP page, including the static include file. However, the <% @ Page%> directive does not work on dynamic include files, such as <jsp:include>



You can use multiple <% @ Page%> instructions on one page, but the attributes can only be used once, but there is one exception, which is the import attribute. Because the Import property is similar to the import statement in Java (referencing the Java Language), you can use this attribute more than once.



Regardless of where you put the <% @ Page%> instruction in the JSP file, it is scoped to the entire JSP page. However, for the readability of JSP programs, as well as good programming habits, it is best to put it in the top of the JSP file.



Property

Language= "Java"

Declare the type of scripting language, temporarily only "Java"



Extends= "Package.class"

Specify the full name of the Java class to be added to the JSP compilation, but use it sparingly, limiting the ability of the JSP to compile.



import= "{package.class | package.*}, ..."

A list of Java packages that need to be imported, which act on program segments, expressions, and declarations.



The following package was imported when the JSP was compiled, so you do not need to specify:



java.lang.*

javax.servlet.*

javax.servlet.jsp.*

javax.servlet.http.*



Session= "true | False

Set whether the client needs an HTTP session. (The person who has studied ASP should be familiar with it) if it is true, then the session is useful.



If it has false, then you cannot use the Session object and define the Scope=session <jsp:useBean> elements. Such use can result in errors.



The default value is true.



Buffer= ' None | 8kb | SIZEKB "

The size of the buffer is used by the out object to process the output of the JSP to the client browser. The default value is 8KB



Autoflush= "true | False

Set if the buffer overflows, whether the output needs to be forced, if its value is defined as true (the default), the output is normal, and if it is set to false, if the buffer overflows, an unexpected error occurs. If you set the buffer to none, Then you can't set the AutoFlush to False.



Isthreadsafe= "true | False

Sets whether a JSP file can be used more than a thread. The default value is true, that is, the JSP can handle requests from multiple users at the same time, and if set to false, a JSP can only process one request at a time



info= "Text"

A text in the execution JSP will be added to the JSP verbatim, and you can use the Servlet.getservletinfo method to retrieve it.



Errorpage= "Relativeurl"

Sets the JSP file that handles exception events.



Iserrorpage= "true | False

Sets whether this page is an error page, and if it is set to true, you can use the exception object.



Contenttype= "mimetype [; Charset=characterset]" | "Text/html;charset=iso-8859-1"

Sets the MIME type. The default MIME type is: text/html, and the default character set is Iso-8859-1.

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.