The page directive

The page directive is used to provide attribute to current JSP page. We can write page directive code anywhere in our JSP page. By convention, page directives are coded first statement of the JSP page.
Syntax of JSP page directive
<%@page attribute="value" %>
Attributes of JSP page directive
Attribute Default value
autoFlush "true"
buffer 8kb
contentType text/html; charset=ISO-8859-1
errorPage url
isELIgnored "false"
isErrorPage "false"
isThreadSafe "true"
language "java"
pageEncoding ISO-8859-1
session "true"

1. The autoFlush Attribute:
The autoFlush attribute specifies whether buffered output should be flushed automatically when the buffer is filled, or whether an exception should be raised to indicate buffer overflow.
If autoFlush value is true (default) indicates automatic buffer flushing when it is full. <%@ page autoFlush="true" %> If autoFlush value is false, a runtime exception is raised to indicates buffer is overflow. <%@ page autoFlush="false" %>
2. The buffer Attribute:
The buffer attribute specifies buffering model for the output stream to the client. If the value is "none" to specify no buffering so that all servlet output is written immediately directed through to the ServletResponse by a PrintWriter. <%@ page buffer="none" %> If buffer size is specified (for example 16 kb ), output is buffered with a buffer size not less than 16 kilobytes: <%@ page buffer="8kb" %>
3. The contentType Attribute:
The contentType attribute defines the character encoding for the JSP page and the MIME type and for the generated response of the JSP page. The default content type is text/html, which is the standard content type for HTML pages. <%@ page contentType="text/html" %>
4. The errorPage Attribute:
The errorPage attribute defines the URL to another JSP apge within the current web applicatio, when an JSP page invokes a checked or unchecked exception thrown. <%@ page errorPage="loginErrorPage.jsp" %>
5. The isErrorPage Attribute:
The isErrorPage indicates whether the current JSP page is an error page; that is, the page that will be displayed when an uncaught exception occurs in the other JSP page in which errorPage="url" match this page and IsErrorPage value is true.
<%@ page isErrorPage="true" %>
6. The extends Attribute:
The extends attribute is used to extends a fully qualified class name of the superclass. <%@ page extends="ns.Product" %>
7. The import Attribute:
The import attribute define same meaning as import statement in Java class. It is also used in JSP page directive to import package, class, interface and related all memebers. By default, a container automatically imports java.lang.*, javax.servlet.*, javax.servlet.jsp.*, and javax.servlet.http.*. When we import sinlge packages, use the following page directive: <%@ page import="java.sql.*" %> When we import multiple packages , specify them separated by comma as follows: <%@ page import="java.sql.*,java.util.*" %>
8. The info Attribute:
The info attribute is used to define an information of the JSP. <%@ page info="This is a use login validate JSP page " %>
9. The isThreadSafe Attribute:
Java and JSP page supported multiple thread. When we want to specify the isThreadSafe option marks a page as being thread-safe. By default, all JSPs are considered thread-safe and isThreadSafe value is true. If the isThreadSafe value to false, the JSP engine makes sure that only one thread at a time is executing our JSP. <%@ page isThreadSafe="false" %>
10. The language Attribute:
The language attribute exists in case future JSP containers support multiple languages. By defalut this attributes value is Java. <%@ page language="java" %>
11. The session Attribute:
The session attribute indicates whether or not the JSP page uses HTTP sessions. A value of true means that the JSP page has access the implict object named session , which referes to the javax.servlet.http.HttpSession interface is available and can be used to access the current/ new session for this page. By defalut the session object value is true.
<%@ page session="true" %>
If session value is false, the session object is unavailable.
12. The isELIgnored Attribute:
The isELIgnored option gives you the ability to disable the evaluation of Expression Language (EL) expressions. <%@ page isELIgnored="false" %>
13. The pageEncoding Attribute:
The pageEncoding attribute determines which type of encoding system is used in JSP page.
<%@ page pageEncoding="ISO-8859-1" %>


Latest Tutorial

Most Visited Tutorial