JSP Page Directive

tutorial and example
tutorial and example

JSP page directive provides various attributes with unique properties. These attributes can be applied to an entire JSP page. The syntax of Page directive is as follows: –

Page directive tag can be placed anywhere inside the JSP page but placing it as the first statement is more preferable.

Attributes of Page Directive

These are the following attributes of page directive: –

language

This attribute defines the scripting language used in JSP page. By default, Java is used as a scripting language.

Syntax: –

contentType

In servlets, we required to set the type of content on response attribute.

Like servlets, JSP use contentType attribute to define MIME type and character set of the response message. The default expression is: –     

buffer

This attribute is use to buffer the response objects. Here, value represents the size of buffer. Instead of passing numeric value, it also allows to declare none. In this case, buffer uses its default size that is 8kb.

Syntax: –

info

In servlets, getServletInfo() method returns the information about the servlet. The similar role is played by info attribute in JSP. Hence, this attribute provides any type of description or information in a form of string.

Syntax: –

autoFlush

The purpose of this attribute is to flush the buffer automatically. For this, the value of autoFlush must be true.

Syntax: –

The default value of autoFlush is always true.

isThreadSafe

The role of isThreadSafe attribute is similar to SingleThreadModel interface in Servlet. Thus, it ensures that JSP handle only one type of request at a time.

Syntax: –

Here, the default value is true.

extends

The extends attribute inherits the superclass to serve its properties in current class. It is similar to extends keyword in Java.

import

This attribute is used to import packages in JSP page. The package consists of similar type of classes and interfaces. It is similar to import keyword in Java.

session

Sessions are used to recognize the user. By default, the value of session is true in JSP. Hence, JSP always establish a session unless we make the value false.

errorPage

This attribute redirects the current page to JSP exception page if any exception occurs.

Syntax: –

Here, URL of JSP exception page is passed.

isErrorPage

This attribute specifies that the current JSP page contain an error page. This error page can be utilized only when exception occur.

Syntax: –

The default value of isErrorPage is always false.

isELIgnored

This attribute can be used to enable or disable the usage of Expression Language tags. By default, the value is true.

Thus, if there is no requirement of Expression Language tag then it can be disabled from JSP page.