JSP Directives

tutorial and example
tutorial and example

In JSP, the role of directive is to provide directions to the JSP container regarding the compilation of JSP page. Directives convey information from JSP page to container that give special instruction at translation time.

The three types of directive provided by JSP is as follows: –

  • Taglib Directive
  • Include Directive
  • Page Directive

Taglib Directive

Taglib directive is used to define tag libraries in JSP page. It enables user to use custom tags within JSP file. A JSP page can contains more than one taglib directives.

Syntax of Taglib Directive

<@ taglib uri=”uri” prefix=”value”>

Here, uri represents the path of tag library description and prefix represent the name of custom tag.

Example of Taglib directive

Here is a simple example of taglib directive. To run this code you need to add jstl jar file within lib directory of your project. It is better to run this code after learning JSTL.

index.jsp

Output:

We will learn more about taglib directive in JSP custom tag.