- A jsp directive is a translation time instruction to the jsp engine.
- we have three kinds of directives.
- Page directive
- Include directive
- Taglib directive
- Page directive is one of the three translation time instructions to the jsp engine.
- Page directive has 13 attributes.
- Mostly page directive used to import java packages in to jsps
<% @ page import="java.sql.*, java.util,*"%>
Jsp Page directive attributes:
Session:The session attribute indicates that whether or not the JSP page uses HTTP sessions. If it is tree means that the JSP page has access to a
existing session object and it is false means that the JSP page cannot access the built-in session object.
Example:<%@ page session="true"%>
isErrorPage:In JSp Page IsErrorPage indicates that whether or not the current page can act as a error page or not.If it is true it is Supposed to handle the Errors..
Example:<%@ page isErrorPage="false"%>
The following directive displays MyErrorPage.jsp when all uncaught exceptions are thrown
Example:<%@ page errorPage="error.jsp"%>
contentType :The contentType attribute defines the MIME(Multipurpose Internet Mail Extension) type of the HTTP response.
Example:<%@ page contentType="text/html; charset=ISO-8859-1"%>
isThreadSafe:isThreadSafe option tells that a page as being thread-safe. By default, all JSPs are considered thread-safe.
If you set the isThreadSafe is false, the JSP engine makes sure that only one thread at a time is executing your JSP.
Example:<%@ page isThreadSafe="true"%>
extends:Indicates the superclass of servlet when jsp translated in servlet.
Example:<%@ page extends="com.Connect"%>
info:This attribute simply sets the information of the JSP page which is retrieved later by using getServletInfo() method of Servlet interface.
Example:<%@ page info="created by instanceofjava" %>
language:language tells the server about the language to be used in the JSP file.
Presently the only valid value for this attribute is java.
Example:<%@ page language="java"%>
autoflush:autoflush attribute true indicates that the buffer should be flushed when it is full and false indicates that an exception should be thrown
when the buffer overflows.
Example:<%@ page autoFlush="true"%>
Buffer:The buffer attribute sets the buffer size in kilobytes to handle output generated by the JSP page.The default size of the buffer is 8Kb.
Example:<%@ page buffer="8kb"%>
Advantage of Include directive:
TLD (Tag Library Descriptor) is used for file to define the tags.