JSP directive allow us to define our page information of JSP and translate these information to JSP engine. According to this page information, JSP engine process further task. This can be an importing java packages into JSP for processing java classes and method, enabling session for current JSP page, making thread safe, limiting buffer size, setting error page.
JSP Directive tags is following
1. Page
2. Include
3. taglib
Include directive are
More on include directive
Page directive
Page directive are having these attributes
import
Import is used to import java classes and package methods.This translates JSP engine to include classes in JSP servlet.
<%@ page import="java.sql.*,java.text.SimpleDateForamt,com.myapp.ClassName"%>
Comma is used to separation between classes and package.
We can use this class as our requirement.
<%!
ClassName cn=new ClassName();
cn.MethodName();
%>
contentType
content type is used to defined mime type and character set in JSP page. This MIME type define page type as, pdf, html, excel or word file. Character set define charater coding. Different language uses different charset.
contentType="MIME Type;charset=characterset"
<%@ page contentType="text/html;charset=ISO-8859-1" %>
errorPage
errorPage=”relativeURL”
When an exception is occur in JSP, errorPage transfer the control of page to defined URL which is set in errorPage. This is customized presentation of errors to user. If relativeURL found blank, exception will throw on same page.
<%@ page errorPage="error.jsp" %>
isErrorPage
isErrorPage=”false | true”
isErrorPage in JSP translate JSP engine to display exception or not. If set false, we can not use exception objects in JSP page. Default value is true.
<%@ page isErrorPage="true" %>
isThreadSafe
isThreadSafe="true | false"
This attribute translate as JSP class is thread safe or not. In multiple threads, concurrent number of users can request to JSP page. JSP process this request, this results in using variable, code at a same time. We can synchronize request to JSP with this attribute. If
isThreadSafe is false, one request process to JSP at same time, and implement as SingleThreadModel. We suggest to use isThreadSafe in rare cases when really need it.
<%@ page isThreadSafe="true" %>
Buffer
buffer="none | 8k | size"
buffer in page directive specify the buffer size of out object to print on client browser. Default size of buffer is 8k, can change to as requirement.
<%@ page buffer="16kb" %>
autoFlush
autoFlush=”true | false”
when buffer get full it is automatically flush, if it is set as true. In false case, it throws exception of overflow.
<%@ page autoFlush="true" %>
Session
Session=”true | false”
Session attribute in page translate to JSP engine to use session object in current JSP page. If session attribute set as false in page directive we can not use session in current JSP.By default it is true.
<%@ page session="true" %>
isELIgnored
isELIgnored=”true | false”
Expression language tag use in JSP 2.0 version and allow using custom made tags. This is almost same as old <%%> tag provide more facility and separate java code and html.
If attribute set as false then we can not use EL tags in JSP.
language
language=”java”
language attribute define core language use in scripting tag. Currently it is java only.
<%@ page language="java" %>
extends
extends=”class.package.ClassName”
extends is used to override the class hierarchy provided by JSP container. It is something like to deploy own our classes instead of using JSP container classes. It should be used with precaution unless you know it clearly. It is used when we need tag libraries.
<%@ page extends="com.myapp.ClassName" %>
info
info=”String”
info is used to provide a String particular to JSP page. This can be a comment on page or any information related to page, this information can get by getServletInfo method of servlet.
<%@ page info="This page is made on 01-May-2011" %>
pageEncoding
pageEncoding=”character set”
pageEncoding attribute is used to define character encoding for the page. This encoding can be UTF-8, ISO-8859-1. If it is not included, default encoding takes ISO-8859-1.
<%@ page pageEncoding="ISO-8859-1" %>
|