JSP vs ASP
  Sample JSP Program
  core JSP
  Jsp Directives
  Jsp Std Actions


Jsp Directives

Jsp Directives
Include Directive
Page directive
Tag Directive

1. Include Directive

This directive is useful to include a html or text or JSP code in

JSP Syntax
<%@ include file="relativeURL" %>

include.jsp: ---- (1)
<head><title>An jsp include directive Test</title></head>
<font color="Red">
The current date and time are
<%@ include file="date1.jsp" %> ---- (2)

date1.jsp: ---- (3)
<%@ page import="java.util.*" %> ---- (4)
<%= (new java.util.Date() ).toLocaleString() %> ---- (5)

Displays in the page:
The current date and time are
Aug 30, 1999 2:38:40

(1) include.jsp is the main jsp program
(2) include directive used to include date1.jsp program
(3) date1.jsp (sub jsp program)
(4) page directive used to import packages
(5) Expression statement used to print date in the html (or response)


An include directive is used to inserts a text file , jsp file or a html file. A static include means that, when you include text, we will call that include static include. When you include jsp those statements will be included in the main jsp and compiled, these type of includes are called dynamic includes.

The JSP page might be recompiled if the included file changes.

2. Page directive

This directive is a very important directive used to import packages and to define global characterstics of jsp program.

JSP Syntax

<%@ page
[ language="java" ]
[ extends="package.class" ]
[ import="{package.class | package.*}, ..." ]
[ session="true|false" ]
[ buffer="none|8kb|sizekb" ]
[ autoFlush="true|false" ]
[ isThreadSafe="true|false" ]
[ info="text" ]
[ errorPage="relativeURL" ]
[ contentType="mimeType [ ; charset=characterSet ]" |
"text/html ; charset=ISO-8859-1" ]
[ isErrorPage="true|false" ]
[ pageEncoding="characterSet | ISO-8859-1" ]


The scripting language used in scriptlets, declarations, and expressions in the JSP page and any included files. In v1.2, the only allowed value is java.
to define super calss/interface of the packages
import="{package.class | package.*}, ..."
All packages required by jsp program needs to define separated by comma. All these packages will be available to scriptlets, expressions and declations within the jsp page.


If the value is true, the session object refers the new session
If the value is false, you cannot use session object of a <jsp:useBean> element with scope=session
The default value is true.


This attribute specifies the data stream size,thru which program will pass data to browser
The default is 8kb

If this attribute set to true, the buffer will be flushed.
If set to false, an exception will be raised when the buffer overflows.
The default value is true
You cannot set autoFlush to false when buffer is set to none.


If the atrribute set to true, the JSP container can send multiple, concurrent client requests to the JSP page. You should write code in the JSP page to synchronize the multiple client threads.
If you use false, the JSP container sends client requestsone at a time to the JSP page.
The default value is true,


A text string that is incorporated verbatim into the compiled JSP page. You can retrieve the string with the Servlet.getServletInfo() method.
If any error occured in the jsp page, that expection will be handled by the jsp specified the relative url ( you need to specifiy the path of jsp)


If set to true, you can use the exception object in the JSP page. If set to false, you cannot use the exception object in the JSP page.
The default value is false.
contentType="mimeType [; charset=characterSet ]" |

The MIME type and character encoding the JSP page uses for the response. You can use any MIME type or character set that are valid for the JSP container. The default MIME type is text/html, and the default character set is ISO-8859-1.
pageEncoding="characterSet | ISO-8859-1"
The page source character encoding. The value is a IANA charset name. The default character encoding is ISO-8859-1.

3. Tag Directive

If you want to use custom tags inside the jsp page, you can include tag libraries using taglib directive

JSP Syntax
<%@ taglib uri="URIForLibrary" prefix="tagPrefix" %>


<%@ taglib uri="http://www.geocities.java.com/tags" prefix="ram" %>
... </ram :loop>

If you are developing or using custom tags, you cannot use the tag prefixes jsp, jspx, java, javax, servlet, sun, and sunw, as they are reserved by Sun Microsystems.


Drona Tutorials - jsp tutorial tutorials