Include Directive in JSP

How is Page Directive used in JSP?


Usually a page directive tag specifies the attributes that are common to the whole JSP page.


<%@ page [language="" ] [ extends="" ] [ import="" ]
[ session="t|f" ] [ buffer="" ] [ autoFlush=" " ]
[ isThreadSafe=" " ][ info=" " ] [ errorPage=" " ]
[ contentType=" " ] [ isErrorPage=" " ] %>

Following table lists the atrributes of Page Directive.
Attributes Description
language Specifies the language used in the page,for JSP it can be only "java".
extends Specifies whether the page uses an extended class
import Specifies the classes to be imported
session It is used to make a session value available to a jsp page, this attribute has a "boolean" value and its "true" by default.
autoflush This is used to flush the buffer if it is set to "true" else it will not.
buffer Specifies the pages buffer size
isThreadSafe Specifies multi threading if it is set to "true", if set to "false" only one request is sent.
errorPage Specifies the error page location for unhandled exceptions.
contentType Specifies the content and mime type.
isErrorPage Specifies whether to use the exception object,it is set to "true" to use the exception object, else it can be set to "false".

Example :

<%@page contentType="text/html" import="java.util.Date" %>
<p>Current Date is ::</p>
<%= new java.util.Date() %>
Result :

Current Date is ::
Thu Dec 10 11:22:56 IST 2009

In the above example we have used the page directive attribute "import" to import the java class "java.util.Date", using this class the current date is displayed using the new instance of the class.

Ask Questions

Ask Question