Java Reference
In-Depth Information
Sidebar 16.2 Java web applications
The Java 2 Enterprise Edition includes several technologies to build web applica-
tions (Bodoff et al . 2002). We are interested in web components, i.e. those items
that provide dynamic content when a web client (e.g. a web browser) connects to
the application.
J2EE provides two main technologies to develop web components: Java Servlets
and Java Server Pages (JSPs). They are equivalent and can be used interchange-
ably. Servlets are best suited to managing the control functions of an application,
such as dispatching requests and handling non-textual data. JSPs are more appro-
priate for generating text-based markup such as HTML, WML and XML.
Servlets are Java classes that implement the Servlet (or HttpServlet ) interface.
JSP are text-based documents that contain two types of text: static template data
(e.g. HTML elements) and JSP elements. The JSP elements are enclosed within
<% ” and “ %> ”.
The web components are Java classes that are contained in an application
called “web container”. The web container receives HTTP requests and dispatches
them to the appropriate web component. We prefer not to go into details about
web components here. The reader can find more information in, for example,
Bodoff et al . (2002).
The web components can maintain information about a user session. The
session can contain several attributes that are associated with a user; in JSP it is
accessible through the object “session”. In addition it is possible to store informa-
tion that is shared by all sessions of the application. This is the web context and is
accessible in JSP though the object “application”.
Web applications run inside a container. Thus, in order to run, the applications
must be deployed to the container. The deployment of Java web applications is
based on a standard directory structure:
/: the root directory contains the static pages and the JSPs.
/WEB-INF : contains the application descriptor in the file web.xml .
/WEB-INF/classes : contains all the classes required by the application, including
the servlet classes.
/WEB-INF/lib : contains the libraries in the form of .jar files.
The method of deployment can vary according to the web container. Using the
Tomcat container the deployment consists of copying the deployment structure
into a new directory under the webapps directory of the Tomcat installation
The initial page ( index ) is a static HTML page, it contains a form where the
user can specify his name, and this information is processed by the JSP
login , which presents to the user a form to specify all the mail server par-
ameters. Then the JSP main provides a list of the email messages contained
in the user's mailbox. Each message can be read in detail by means of the
JSP message that shows the contents of a given message. Both main and
message make use of the javax.mail package to access the information stored
on the mail server. Finally the JSP logout closes the connection.
Search WWH ::

Custom Search