- 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:
- 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:
- import
- session
- isErrorPage
- errorPage
- ContentType
- isThreadSafe
- extends
- info
- language
- autoflush
- buffer
import:
This attribute defines the list of packages,each separated by comma.
Syntax:
import="package.class"
Example:
<%@page import="java.util.*,java.io.*"%>
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 aexisting session object and it is false means that the JSP page cannot access the built-in session object.
Syntax:
session="true|false"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..Syntax:
isErrorPage="true|false"Example:
<%@ page isErrorPage="false"%>errorPage:
The errorPage attribute tells the JSP engine which page to display if there is an error while the current page runs.
The value of the errorPage attribute is a relative URL.The following directive displays MyErrorPage.jsp when all uncaught exceptions are thrown
Syntax:
errorPage="url"Example:
<%@ page errorPage="error.jsp"%>contentType :
The contentType attribute defines the MIME(Multipurpose Internet Mail Extension) type of the HTTP response.Syntax:
contentType="MIME-Type"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.
Syntax:
isThreadSafe="true|false"Example:
<%@ page isThreadSafe="true"%>extends:
Indicates the superclass of servlet when jsp translated in servlet.Syntax:
extends="package.class"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.Syntax:
info="message"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.
Syntax:
language="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 thrownwhen the buffer overflows.
Syntax:
autoflush="true|false"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.Syntax:
buffer="sizekb|none"Example:
<%@ page buffer="8kb"%>include Directive:
The include directive is used to include the contents of any resource it may be jsp file, html file or text file.
It allows a JSP developer to include source code of a file inside jsp file at the specified place at a translation time.
Advantage of Include directive:
Code Reusability
Syntax:
<%@ include file="sourceName"%>
Example:
<%@ include file="/foldername/fileName"%>
taglib Directive:
The taglib directive makes custom actions available in current page through the use of tag library.
TLD (Tag Library Descriptor) is used for file to define the tags.
TLD (Tag Library Descriptor) is used for file to define the tags.
Syntax:
<%@ taglib uri="path" prefix="prefix"%>
Example:
<%@ taglib uri="http://www.instanceofjava/tags" prefix="mytag"%>
No comments