JSP Directives

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
</html>
<head>
<title>Tutorial and Example</title>
</head>
<body>
<h2 align="center">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:out value="Welcome to JSP Taglib Directive"/>
</h2>
</body>
</html>
Output: We will learn more about taglib directive in JSP custom tag.