A JSP element that gives an instruction to the JSP container and is interpreted at translation time.
In advanced Java, a JSP directive is a special type of instruction that provides global information about an entire JSP page. It is used to convey information to the container, which is responsible for managing the JSP page’s execution. The JSP directive is defined using the <%@ directive %>
syntax.
There are three types of JSP directives:
- Page Directive (
<%@ page %>
): This directive is used to define attributes that apply to the entire JSP page. Some common attributes include error page, language, contentType, import, session, buffer, autoFlush, isThreadSafe, and more.Example:jsp<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
- Include Directive (
<%@ include %>
): This directive is used to include a file at the time the page is translated into a servlet. It is similar to using theinclude
directive in other programming languages.Example:jsp<%@ include file="header.jsp" %>
- Taglib Directive (
<%@ taglib %>
): This directive is used to define and use tag libraries in a JSP page. It declares the tag library descriptor (TLD) file that contains the information about the custom tags.Example:jsp<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
These directives help in configuring and customizing the behavior of JSP pages during translation and execution.