Java Server Pages Overview
 
Directives
 
Directives as its name implies are compile time organize tags. They permit us to modify how our JSP pages are compiled to Java Servlets.
 
There are three types of Directive:
1. Page Directive
2. Taglib Directive
3. Include Directive
 
The Page Directive
This directive is positioned at the top of a JSP page and allows you to customize different features of your JSP page.
 
It's syntax:
<%@ page attribute-name="value" %>
 
All JSP directives, scripting elements and expressions lie in between the <% and %> tags.
Following are the different attributes available to us along with the values we can use in our JSP page.
 
Attribute Value Description
language scriptingLanguage The language we are using on the JSP page. Default is Java.
extends className The Java class which our generated Servlet will be extending.
import importList A comma separated list of classes, interfaces and packages we want to use in our JSP page.
session true | false If we want to use session then set it to true, otherwise false. Default is true.
buffer none | sizeInKB Set it to none if we doesn't want to use buffering or set it to a value greater than 8KB. Default is 8KB.
autoFlush true | false If set to true, once buffer is full it will be sent to the client. If set to false then an exception will be generated on buffer overflow. Default is true.
isThreadSafe true | false If set to true then the JSP engine will send all the requests as they come to the same instance of the Servlet. If false then request will be sent to the Servlet one at a time. Default is true.
info servletInfo Returns info about the JSP page.
errorPage pageURL The URL to the JSP page where all un-handled exceptions will be sent.
isErrorPage true | false If this JSP page is the error page where other JSP page's un-handled exceptions will be sent then set it to true, otherwise false.
contentType content/type The content-type for the current JSP page. Default is text/html.
pageEncoding encodingInfo Character encoding for the JSP page. Default is ISO-8859-1.
 
 
The Taglib Directive

It is used to incorporate custom tags in a JSP page.

 
It requires two attributes and it's syntax is as :
<%@ taglib uri="tag-lib-uri" prefix="tag-prefix" %>
 
The uri attribute contains the location of the tag library TLD (Tag Library Descriptor) file, while prefix is the tag prefix you want to use for our custom tag e.g,
<%@ taglib uri="/WEB-INF/tlds/mytag.tld" prefix="star" %>
<star:time />
 
Above code describes a tag with prefix 'star' which displays current time.
 
 
The Include Directive
The include directive allows insertion of the content of another file into the JSP page at compilation time.
 
It's syntax is as follows :
<%@ include file="localOrAbsoluteURL" %>
 
During compilation the content of the file specified in the file attribute will be added to the current JSP page e.g,
... Some HTML and JSP code above
<%@ include file="/misc/ebiz.txt" %>
</body>
</html>
 
Above code adds the ebiz info to the current JSP page.