You are on page 1of 3

JSP directives instruct the JSP container on how to work with JSPs.

There are three directives in the JSP specification: page, include and taglib. The directive form usualy follows the following form:
<% directive attribute1 = "value 1" @ attribute2 = "value 2" ... %>

page Directive
The page directive allows you to define one or more following attributes:

import Option
import="package.class" import="package.class1,...,package.classN" Import option allows you to specify which classes or packages are used in the page. for example, you can import all the classes in the package java.util as follows: <%@ page import="java.util.*" %> You can use import option multiple times in the page directive.

contentType Option
contentType="MIME-Type" contentType="MIME-Type; charset=Character-Set". The contentType option allows you specify the MIME type of the output page. The default istext/html you can also use other values such as text/plain for outputing text format such as <%@ page contentType="text/plain" %>

isThreadSafe Option
isThreadSafe="true|false". isThreadSafe option allows you to indicate the page is being processed as thread-safe. The default value of the isThreadSafe is true therefore all JSPs are considered thread-safe. IfisThreadSafe is set to false, JSP engine ensures that only one thread at a time is executingthe current JSP page.

session Option
session="true|false". By using session option, you are telling JSP compiler that you want to use session or not. The default value of the session attribute is true, indicating that there is an implicit variable called session is available for your use.

buffer and autoFlush Options
buffer and autoFlush options let you control the JSP buffering. You can turn buffer on or off or even specify the buffer size by using buffer option such as: <%@ page buffer="none" %> <%@ page buffer="64kb" %> autoFlush option controls whether the buffer is flushed automatically when it is full. The default value of autoFlush is true means JSP automatically flush the buffer when it is full.

Info Option
Info option allows you to define the description of the servlet. Later on you can access this value by calling the method:

For example: <%@ page errorPage="error. the JSP compiler always assumes that the file is in the same directory as the JSP page. The syntax of include directive is as follows: <%@ include file="relative url" %> The filename you specify in the include directive is a relative URL. And in the JSPs you use theextends option to use that supper class in you JSP page. extends Option In some cases.getMessage()%>.jsp" %> isErrorPage Option isErrorPage option indicates that the current JSP page can be used as an error page for other JSP page. navigation bar. When you set isErrorPage equal true.Servlet. JSP engine creates an implicit exception object which contains the Throwable object that caused the error page to be called. to make those section reusable in every JSP page. taglib Directive JSP has a set of standard tags for you to use. you can print out the error message to the user.. for example: <% page isErrorPage="true" %> @ <html> <head> <title>Error Occurred</title> </head> <body> <h1>Error</h1> An error occurred while processing your request. In this case. errorPage Option errorPage option allows you to indicate the error page to be displayed when the error occurs in the current executing page. In order to do so.</p> Please contact the System Administrator for advices. JSP also provide a possibility to allow you to create new custom tags look like HTML and XML tag. isELIgnored Option isELIgnored option provide the ability for you to disable the evaluation of the expressionlanguage (EL)..getServletInfo(). By using this excpetion object. first you need to create a super class first. you can use taglib directive to use your custom . You will learn more about expression language in the later tutorial. Normally the include directive is used to include common sections of a JSP page in a webapplication or website such as header. This supper class normally inherits from the HttpServlet class. </body> </html> Include Directive Include directive lets you to include a file (JSP or HTML) at the time JSP engine translatethe JSP page into a servlet. <p> The error message is: <%= exception. you need to create your own super class of JSP pages and using this supper class in different JSPs. footer. If you provide a file name without associated path.

tag in your JSP page. you can refer to the custom tag tutorial. For using custom tag. The syntax of using taglib directive is as follows: <% taglib uri="http://localhost/jsptutorial/taglib/mytaglib" @ prefix="jsptutorial" %> .