JSP Directives:

Introduction :

A JSP directive gives special information about the page to JSP Engine at page translation time.JSP directives serve as a message from a JSP page to the JSP container and control the processing of the entire page.

Directives are always enclosed within <%@ ... %> tag.

There are three types of directive: page,include and taglib .


Page directive :

The page directive allows to apply different attributes that is to be added to a JSP. These attributes gives special processing information to the JSP engine which allows the way of processing JSP pages.

Introduction :

A JSP directive gives special information about the page to JSP Engine at page translation time.JSP directives serve as a message from a JSP page to the JSP container and control the processing of the entire page.

Directives are always enclosed within <%@ ... %> tag.

There are three types of directive: page,include and taglib .

Page directive :

The page directive allows to apply different attributes that is to be added to a JSP. These attributes gives special processing information to the JSP engine which allows the way of processing JSP pages.




Following are the various page directives that are used in JSP

  • language
  • extends
  • import
  • session
  • buffer
  • autoFlush
  • isThreadSafe
  • errorPage
  • info
  • isErrorPage
  • contentType

AttributeDescriptionSyntaxExample
language This attribute is used to specify the language whose statements are allow inside the JSP.Currently the only valid value for this attribute is java. language="java" <%@ page language= "java" %>
Import Import attribute is used to specify the package which you want to import for the translated servlet class. import=" package.class " <%@ page import= "java.util.*, java.io.*" %>
Extends Indicates the superclass of servlet when jsp translated in servlet. extends=" package.class " <%@ page extends= "com.Connect"%>
Session Possible values for this attributes are true/false default value is true. If you specify the session value as false then session implicit object will be disabled. session=" true |false"<%@ page session= "true" %>
Buffer specifies the buffer size for out and default is 8kb. buffer=" size kb|none" <%@ page buffer= "8kb" %>
isThreadSafe True indicates multi threading and false indicates that the servlet should implement SingleThreadModel isThreadSafe=" true | false" <%@ page isThreadSafe="true"%>
autoFlush 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. autoflush =" true |false" <%@ page autoFlush= "true" %>
Info This defines a string that can be retrieved via the getServletInfo method. info=" message " <%@ page info="This is a simple jsp file "%>
pageEncoding This defines data type of page encoding. pageEncoding="ISO-8859-1" <%@ page pageEncoding="ISO-8859-1"%>
contentType This specifies the MIME type of the output. contentType=" MIME-Type " <%@ page contentType="text/html; charset=ISO-8859-1"%>
isELIgnored This defines ENUM data type. isELIgnored=" true| false " <%@ page isELIgnored="false"%>
isErrorPage This indicates whether or not the current page can act as the error page. isErrorPage="true| false " <%@ page isErrorPage="false"%>
errorPage Define a URL to another JSP that is invoked if an unchecked runtime exception is thrown. errorPage=" url " <%@ page errorPage="error.jsp"%>

taglib directive :

it is used to use the custom tags developed by you in JSP & also used to use JSTL tags inside the JSP.

Syntax:<%@taglib uri="some uri" prefix="some prefix"%>

Include Directive :

It is used to include one Jsp or Html to another JSP.

Syntax:<%@ include file="abc" %>

Example:

<% @ include file="/header.jsp"%>





comments powered by Disqus