• A jsp directive is a translation time instruction to the jsp engine.
  • we have three kinds of directives.
  1. Page directive
  2. Include directive
  3. 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:

  1. import
  2. session
  3. isErrorPage
  4. errorPage
  5. ContentType
  6. isThreadSafe
  7. extends
  8. info
  9. language
  10. autoflush
  11. 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 a
existing 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 thrown
when 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.

Syntax:

<%@ taglib uri="path" prefix="prefix"%>

Example:


<%@ taglib uri="http://www.instanceofjava/tags" prefix="mytag"%>




Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu