Signup/Sign In

JSP Directive Tag

Directive Tag gives special instruction to Web Container at the time of page translation. Directive tags are of three types: page, include and taglib.

<%@ page ... %>defines page dependent properties such as language, session, errorPage etc.
<%@ include ... %>defines file to be included.
<%@ taglib ... %>declares tag library used in the page

We'll discuss about include and taglib directive later. You can place page directive anywhere in the JSP file, but it is good practice to make it as the first statement of the JSP page.

The Page directive defines a number of page dependent properties which communicates with the Web Container at the time of translation. Basic syntax of using the page directive is <%@ page attribute="value" %> where attributes can be one of the following :

  • import attribute
  • language attribute
  • extends attribute
  • session attribute
  • isThreadSafe attribute
  • isErrorPage attribute
  • errorPage attribute
  • contentType attribute
  • autoFlush attribute
  • buffer attribute

import attribute

The import attribute defines the set of classes and packages that must be imported in servlet class definition. For example

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

language attribute

language attribute defines scripting language to be used in the page.

extends attribute

extends attribute defines the class name of the superclass of the servlet class that is generated from the JSP page.

session attribute

session attribute defines whether the JSP page is participating in an HTTP session. The value is either true or false.

isThreadSafe attribute

isThreadSafe attribute declares whether the JSP is thread-safe. The value is either true or false

isErrorPage attribute

isErrorPage attribute declares whether the current JSP Page represents another JSP's error page.

errorPage attribute

errorPage attribute indicates another JSP page that will handle all the run time exceptions thrown by current JSP page. It specifies the URL path of another page to which a request is to be dispatched to handle run time exceptions thrown by current JSP page.

contentType attribute

contentType attribute defines the MIME type for the JSP response.

autoFlush attribute

autoFlush attribute defines whether the buffered output is flushed automatically. The default value is "true".

buffer attribute

buffer attribute defines how buffering is handled by the implicit out object.