What is Page Directive?

Used to define attributes of jsp page, such as character encoding, content type, import etc.
<%@page attribute1=” ” attribute2=””%>
The attributes of page directive,

import:
Used to import a package.
<%@page import=”java.util.Date”%>
<%@page import=”java.util.*,javax.io.*”%>
Use comma to separate the packages. The quotes go around the entire list of packages. There is no semicolon in the end.
isThreadSafe:
It tells the container whether the page is thread safe with proper synchronization implemented on the page. In other words whether the generated servlet needs to implement SingleThreadModel.
<%@page isThreadSafe=”false”%>
The value true means container can send multiple requests to the page. Here the value is set to false, that means the generated servlet implement the SingleThreadModel.
The default value is true.
contentType:
Defines the MIME type and extra character encoding for the jsp response.
The default value is “text/html”
<%@page contentType=”text/html;charset=UTF-8”%>
isELIgnored:
Defines whether expression language are ignored when the page is translated.
The default it is false.
isErrorPage:
Difines whether the current page represents another jsp’s error page. By default the value is false. If the value set to “true” then page has access to the implicit exception object(which is an implicit object of Throwable), if false the implicit exception object is not available to the jsp page.
errorPage:
Defines an URL to the resource to which uncaught exceptions should be sent. The target URL must be error page(isErrorPage=”true”).
<%@page errorPage=”error.jsp”%>
language:
Defines the scripting language used in scriptlets, expressions and declarations. The default value is java.
extends:
Define a fully classified class name of the super class that the jsp will extend to generate translated page.
session:
Defines whether the page will participate in the HTTP session. If the value is set to true then the page can have access to the implicit session object. The default value is true.
buffer:
Defines how buffering is handled by the out object(reference to JspWriter).
The default value is 8(kb). Output is buffered with a buffer size that is not less than the size specified.
autoFlush:
Defines whether the buffered output is flushed automatically. The default value is true.
info:
Used to set an information string that is incorporated into the page and accessable by using the Servlet.getServletInfo() method.
<%@page info=”this is the login jsp”%>
pageEncoding:
Defines the character encoding for jsp. The default value is “ISO-8859-1” unless the content type defines the encoding or the page uses XML document syntax.

Example:
<%@page contentType=”text/html;charset=UTF-8”
Session=”true” buffer=”16kb” autoFlush=”true”
isErrorPage=”false” isThreadSafe=”true”
info=”this is a page displays the date”
import=”java.util.Date”%>
<html>
<body>
<%= “The current date is”+ new Date()%>
</body>
</html>

No comments:

Post a Comment