JSP directives

In this post, you will learn:

  • What is a directive in JSP?
  • Which directives are supported by the JSP?

What is a directive?

A directive in JSP, represents an instruction to the translator to modify the structure of the auto generated servlet at the time of translation on behalf of the programmer. You have been already told that for each JSP, a servlet class is auto generated. Sometimes modifications are required in this servlet e.g. some extra packages need to be imported in it or it need to be inherited from a user defined class, or exceptions need to be managed in a specific way in it, etc. If this servlet were defined by the programmer, it could have been directly modified but it is generated from the JSP hence directives are provided to programmers so that they can ask the translator to customize the auto generated servlet on their behalf.

A JSP directive has following syntax:

<%@ directiveName attribute=”value” … %>

Information to the translator is provided with the help of attributes. Different directives support different attributes.

JSP directives:

JSP supports following three directives:

1. page: It is used by the JSP programmers to get the structure of auto generated servlet, modified according to their requirements.

2. include: It is used by the JSP programmers to get the contents of a file included to the response of JSP at the time of translation.

3. taglib: It is used by the JSP programmers to use custom tags in a JSP.

In the subsequent posts, use of all these directives is covered in detail.


Its time to recap the main concepts:

  1. A directive is an instruction to the translator to make some modifications in the auto generated servlet at the time of translation on behalf of the programmer.
  2. page, include and taglib are the three directives which are supported in JSP.
  3. Attributes of a directive, are used by the JSP programmer to provide information to the translator.
  4. Different directives support different attributes.
If you like the post, then share it...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *