Java Server Pages - The directives

Ask a question

Introduction to JSP directives

JSP directives are instructions inserted into special HTML tags. The syntax is as follows:
<%@ directive { attribute="value"} %>

JSP directives are used to indicate:
  • the language used
  • classes to include
  • classes to extend
  • ...

Presentation of JSP directives

The version 1.0 Revision B of Java Server Pages JSP provides three guidelines:
  • The page directive provides information on the JSP page. This directive has many attributes (explained below):

<%@ page
[language="java"] [extends="package.class"]
[import="{package.class|package.*}, ..."] [session="true|false"]
[buffer="none|8kb|sizekb"] [autoflush="true|false"]
[isThreadSafe="true|false"] [info="text"]
[contentType="mimeType [charset=characterSet]" |
  • the include directive to include files in the HTML page

<code><%@ include file="relativeURL" %>
  • the taglib directive defining the address and prefix of a library of tags that can be used in the page

<%@ taglib uri="URIToTagLibrary" prefix="tagPrefix" %>
This directive allows the creation of tags of this form:
<tagPrefix:name attribute="value" ... %> ... </tagPrefix:name%>

Attributes of the page directive

Here is the list of attributes for the page directive

AttributPossible valuesDescription
languagejavaSpecifies the language to be used to process to the instructions of the page. Java is the language used predominantly, but servlets can be written in another language
extendspackage.classDefine the class to be extended, that is to say, the parent class of the servlet generated by JSP
import pakage.*Allows you to import a list of classes or packages to top of the page, as for a Java application..
session true>falseSets whether the current page can access the data stored in the session. This attribute is true by default
buffernone/8kb/sizekbSets whether the output stream will be placed in a buffer before sending. Default buffer size is 8kb, but it is possible to set the size in kb. This attribute is used with the autoflush attribute
autoflush true>falseLa valeur true (par défaut) indique que le tampon doit être vidé lorsqu'il est plein
isThreadSafe true>falseTrue indicates that multiple clients can simultaneously uses the servlet. If set to false, the servlet switches to monothread mode, which means that only one client can access the servlet at a time.
infoTextreturn a description using the servlet.getServletInfo() method.
errorPageURLAllows you to specify a JSP page to manage unhandled exceptions.
isErrorPage falseSpecify whether the current page is an error page
contentTypetext/html;charset=ISO-8859-1</b>Indicates the MIME type of the page as well as the character set used

Original document published on