❮ Previous Next ❯

JSP page Directive:

The JSP page directive tells to the web container that pertain to the current JSP page. We can put the code page directives anywhere in your JSP page. But by convention, JSP page directives are coded at the top of the JSP page. The general form of JSP page directive is

<%@ page attribute="value"%>

There are several attributes, which are used along with Page Directives and these are

  1. import
  2. session
  3. isErrorPage
  4. errorPage
  5. ContentType
  6. isThreadSafe
  7. extends
  8. info
  9. language
  10. autoflush
  11. buffer


This attribute is used to import packages. While doing coding you may need to include more than one packages, In such scenarios this page directive's attribute is very useful as it allows you to mention more than one packages at the same place separated by commas (,). Alternatively you can have multiple instances of page element each one with different package.


<%@page import="value"%>

Here value is package name.The following is an example of how to import more than one package using import attribute of page directive.

<%@page import="java.sql.*%> <%@page import="java.io.*%>


Generally while building a user interactive JSP application, we make sure to give access to the user to get hold of his/her personal data till the session is active. Consider an example of logging in into your bank account, we can access all of your data till we signout (or session expires). In order to maintain session for a page the session attribute should be true.

This attribute is to handle HTTP sessions for JSP pages. It can have two values: true or false. Default value for session attribute is true, which means if you do not mention this attribute, server may assume that HTTP session is required for this page.Default value for this attribute: true


<%@ page session="value"%>

here value is either true OR false


<%@ page session="true"%>

The above code would allow a page to have session implicit objects.

<%@ page session="false"%>

If this code is specified in a JSP page, it means session objects will not be available for that page. Hence session cannot be maintained for that page.


This attribute is used to specify whether the current JSP page can be used as an error page for another JSP page. If value of isErrorPage is true it means that the page can be used for exception handling for another page. Generally these pages has error/warning messages OR exception handling codes and being called by another JSP page when there is an exception occurred there.Default value: false


<%@ page isErrorPage="value"%>

Here value is either true OR false.


<%@ page isErrorPage="true"%>


As I stated above, when isErrorPage attribute is true for a particular page then it means that the page can be called by another page in case of an exception. errorPage attribute is used to specify the URL of a JSP page which has isErrorPage attrbute set to true. It handles the un-handled exceptions in the page.


<%@ page errorPage="value"%>

Here value is a JSP page name which has exception handling code (and isErrorPage set to true).


<%@ page errorPage="ExceptionHandling.jsp"%>

This means if any exception occurs on the JSP page where this code has been placed, the ExceptionHandling.jsp (this page should have isErrorPage true) page needs to be called.


This attribute is used to set the content type of a JSP page.

Default value: text/html


<%@ page contentType="value"%>

here value of content type can be anything such as: text/html, text/xml etc.


Below code can be used for text/html pages.

<%@ page contentType="text/html"%>

for text/xml based pages:

' <%@ page contentType="text/xml"%>


Lets understand this with an example. Suppose you have created a JSP page and mentioned isThreadSafe as true, it means that the JSP page supports multithreading (more than one thread can execute the JSP page simultaneously). On the other hand if it is set to false then JSP engine won't allow multithreading which means only single thread will execute the page code.

Default value for isThreadSafe attribute:true


<%@ page isThreadSafe="value"%>

here value can be true OR false.


<%@ page isThreadSafe="false"%>

Only one thread will be responsible for JSP page execution.


This attribute is used to specify the buffer size. If you specify this to none during coding then the output would directly written to Response object by JSPWriter. And, if you specify a buffer size then the output first written to buffer then it will be available for response object.


<%@ page buffer="value"%>

value is size in kb or none.


No buffer for this page:

<%@ page buffer="none"%>

5 kb buffer size for the page, which has below code:

<%@ page buffer="5kb"%>


Like java, here also this attribute is used to extend(inherit) the class.


<%@ page extends="value"%>

Value is package_name.class_name.


The below code will inherit the SampleClass from package: mypackage

<%@ page extends="mypackage.SampleClass"%>


It provides a description to a JSP page. The string specified in info will return when we will call getServletInfo() method.


<%@ page info="value"%>

here value is Message or Description


<%@ page info="This code is given by Chaitanya Singh"%>


It specifies the scripting language( underlying language) being used in the page.


<%@ page language="value"%>

value is scripting language here.


<%@ page language="java"%>


If it is true it means the buffer should be flushed whenever it is full. false will throw an exception when buffer overflows.

Default valueTrue


<%@ page autoFlush="value"%>

value can be true or false.


Buffer will be flushed out when it is full

<%@ page autoFlush="true"%>

It will throw an exception when buffer is full due to overflow condition

<%@ page autoFlush="true"%>

❮ Previous Next ❯

Follow Us


Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Email: info@silantechnology.com
      Phone: 0674-2361252
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved