It allows the developer to declare variables or methods.
Start with <%! and End with %>
Code placed inside this tag must end in a semicolon ( ; ).
Declarations do not generate output so are used with JSP expressions or
scriptlets.
For Example,
<%!
private int counter = 0 ;
private String get Account ( int accountNo) ;
%>
Expression tag
Expression tag ( <%= %>)
Expression tag allow the developer to embed any Java expression and is short for
out.println().
A semicolon ( ; ) does not appear at the end of the code inside the tag.
e.g.to show the current date and time.
Date : <%= new java.util.Date() %>
Directive tag
Direcitve tag ( <%@ directive...>)
A JSP directive gives special information about the page to JSP Engine.
Three main types of directives are:
1) page - processing information for this page.
2) Include - files to be included.
3) Tag library - tag library to be used in this page.
Directives do not produce any visible output when the page is requested but
change the way the JSP Engine processes the page.
e.g.,you can make session data unavailable to a page by setting a page
directive (session) to false.
1. Page Directive
This directive has 11 optional attributes that provide the JSP Engine with
special processing information. The 11 different
attributes with a brief description is decribe in table given below:
Language
Which language the file uses.
<%@ page language = "java" %>
Extends
Superclass used by the JSP engine for
the translated Servlet.
<%@ page extends = "com.taglib... %>
import
Import all the classes in a java
package into the current JSP page. This allows the JSP page to use
other java classes.
<%@ page import = "java.util.*" %>
session
oes the page make use of sessions. By
default all JSP pages have session data available. There are
performance benefits to switching session to false.
Default is set to true.
buffer
Controls the use of buffered output
for a JSP page. Default is 8kb
<%@ page buffer = "none" %>
autoFlush
Flush output buffer when full.
<%@ page autoFlush = "true" %>
isThreadSafe
Can the generated Servlet deal with
multiple requests? If true a new thread is started so requests are
handled simultaneously.
info
Developer uses info attribute to add
information/document for a page. Typically used to add
author,version,copyright and date info.
<%@ page info = "visualbuilder.com test
page,copyright 2001. " %>
errorPage
Different page to deal with errors.
Must be URL to error page.
<%@ page errorPage = "/error/error.jsp"
%>
IsErrorPage
This flag is set to true to make a JSP
page a special Error Page. This page has access to the implicit
object exception (see later).
contentType
Set the mime type and character set of
the JSP.
2. Include directive
It allows a JSP developer to include contents of a file inside another.
Typically include files are used for navigation,headers,tables and footers that
are common to multiple pages.
Two examples of using include files:
This includes the html from privacy.html found in the include directory into the
current jsp page.
<%@ include file = "include/privacy.html" %>
or to include a naviagation menu (jsp file) found in the current directory.
<%@ include file = "navigation.jsp" %>
3. Tag Lib directive
A tag lib is a collection of custom tag that can be used by the page.
There are three main roles of action tag :
1)����It enable the use of server side Javabeans
2)����It transfer control between pages
3)����Browser independent support for applets.
Javabeans
A Javabeans is a special type of class that has a number of methods. The
JSP page can call these method so can leave most of the code in these Javabeans.
For example,if you wanted to make a feedback form that automatically sent out an
email. By having a JSP page with a form,when the visitor presses the submit
button this send the details to a Javabean that sends out the email. This way
there would be no code in the JSP page dealing with sending emails (JavaMail
API) and your Javabeans could be used in another page (promoting reuse).
To use a Javabeans in a JSP page use the following syntax:
<jsp : usebean id = " ...." scope = "application" class = "com..." />
The following is a list of Javabean scopes:
page - valid until page completes.
request - bean instance lasts for the client request
session - bean lasts for the client session.
application - bean instance created and lasts until application ends.