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
There are several attributes, which are used along with Page Directives and these are
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.
Here value is package name.The following is an example of how to import more than one package using import attribute of page directive.
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
here value is either true OR false
The above code would allow a page to have session implicit objects.
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
Here value is either true OR false.
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.
Here value is a JSP page name which has exception handling code (and isErrorPage set to true).
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
here value of content type can be anything such as: text/html, text/xml etc.
Below code can be used for text/html pages.
for text/xml based pages:
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
here value can be true OR 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.
value is size in kb or none.
No buffer for this page:
5 kb buffer size for the page, which has below code:
Like java, here also this attribute is used to extend(inherit) the class.
Value is package_name.class_name.
The below code will inherit the SampleClass from package: mypackage
It provides a description to a JSP page. The string specified in info will return when we will call getServletInfo() method.
here value is Message or Description
It specifies the scripting language( underlying language) being used in the page.
value is scripting language here.
If it is true it means the buffer should be flushed whenever it is full. false will throw an exception when buffer overflows.
value can be true or false.
Buffer will be flushed out when it is full
It will throw an exception when buffer is full due to overflow condition