JSP Page Directive

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 attribute="value">

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: -

<@page language="Scripting-language">

contentType

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

response.setContentType("text/html");

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

<@page contentType="text/html; charSet=UTF-8">

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: -

<@page buffer="value">

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: -

<@page info="value">

autoFlush

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

Syntax: -

<@page autoFlush="true/false">

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: -

<@page isThreadSafe="true/false">

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.

<@page extends="package.class">

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.

<@page import="package-name">

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.

<@page session="true/false">

errorPage

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

Syntax: -

<@page errorPage="value">

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: -

<@page isErrorPage="true/false">

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.

<@page isELIgnored="true/false">

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