<?xml version="1.0" encoding="UTF-16"?>
<rss version="2.0"><channel><title>SoftXML | JAVATME Tutorials</title><link>http://www.softxml.com/rss/tutorials/javatme.xml</link><description>Tutorials</description><pubDate>Sun, 11 Jan 2009 14:27:51 EST</pubDate><language>en-us</language><image><title>SoftXML | JAVATME Tutorials</title><url>http://www.softxml.com/images/rsscategory.gif</url><link>http://www.softxml.com/rss/tutorials/javatme.xml</link><width>80</width><height>73</height></image><item><title>Java&lt;sup&gt;TM&lt;/sup&gt; Platform, Enterprise Edition 5 (Java EE 5)</title><link>http://www.softxml.com/LearnTutorial.asp?id=2862224685&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;Developers today increasingly recognize the need for distributed, transactional, and portable applications that
leverage the speed, security, and reliability of server-side technology. In the world of
information technology, enterprise applications must be designed, built, and produced for less money,
with greater speed, and with fewer resources.&lt;/p&gt;&lt;p&gt;With the Java&lt;sup&gt;TM&lt;/sup&gt; Platform, Enterprise Edition (Java EE), development of Java enterprise applications
has never been easier or faster. The aim of the Java EE 5
platform is to provide developers a powerful set of APIs while reducing development
time, reducing application complexity, and improving application performance.&lt;/p&gt;&lt;p&gt;The Java EE 5 platform introduces a simplified programming model. With Java EE
5 technology, XML deployment descriptors are now optional. Instead, a developer can simply
enter the information as an annotation directly into a Java source file, and
the Java EE server will configure the component at deployment and runtime. These
annotations are generally used to embed in a program data that would otherwise
be furnished in a deployment descriptor. With annotations, the specification information is put
directly in your code next to the program element that it affects.&lt;/p&gt;&lt;p&gt;In the Java EE platform, dependency injection can be applied to all resources
that a component needs, effectively hiding the creation and lookup of resources from
application code. Dependency injection can be used in EJB containers, web containers, and
application clients. Dependency injection allows the Java EE container to automatically insert references
to other required components or resources using annotations.&lt;/p&gt;&lt;p&gt;The Java Persistence API is new to the Java EE 5 platform. The
Java Persistence API provides an object/relational mapping for managing relational data in enterprise
beans, web components, and application clients. It can also be used in Java
SE applications, outside of the Java EE environment.&lt;/p&gt;&lt;p&gt;This tutorial uses examples to describe the features and functionalities available in the
Java EE 5 platform for developing enterprise applications.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=2862224685&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Java EE Application Model</title><link>http://www.softxml.com/LearnTutorial.asp?id=1597174412&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;The Java EE application model begins with the Java programming language and the
Java virtual machine. The proven portability, security, and developer productivity they provide forms
the basis of the application model. Java EE is designed to support applications
that implement enterprise services for customers, employees, suppliers, partners, and others who make
demands on or contributions to the enterprise. Such applications are inherently complex, potentially accessing
data from a variety of sources and distributing applications to a variety of
clients.&lt;/p&gt;&lt;p&gt;To better control and manage these applications, the business functions to support these
various users are conducted in the middle tier. The middle tier represents an
environment that is closely controlled by an enterprise’s information technology department. The middle
tier is typically run on dedicated server hardware and has access to the
full services of the enterprise.&lt;/p&gt;&lt;p&gt;The Java EE application model defines an architecture for implementing services as multitier
applications that deliver the scalability, accessibility, and manageability needed by enterprise-level applications.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=1597174412&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Distributed Multitiered Applications</title><link>http://www.softxml.com/LearnTutorial.asp?id=13479781032&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;The Java EE platform uses a distributed multitiered application model for 
	enterprise applications. Application logic is divided into components according 
	to function, and the various application components that make up a Java EE 
	application are installed on different machines depending on the tier in the 
	multitiered Java EE environment to which the application component belongs.
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaay.html#bnaaz"&gt;Figure 1-1&lt;/a&gt;
	shows two multitiered Java EE applications divided into the tiers described in 
	the following list. The Java EE application parts shown in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaay.html#bnaaz"&gt;
		Figure 1-1&lt;/a&gt; are presented in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaay.html#bnabb"&gt;
		Java EE Components&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;Client-tier components run on the client machine.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Web-tier components run on the Java EE server.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Business-tier components run on the Java EE server.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Enterprise information system (EIS)-tier software runs on the EIS server.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a name="indexterm-5"&gt;&lt;/a&gt;Although a Java EE application can consist of the 
	three or four tiers shown in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaay.html#bnaaz"&gt;
		Figure 1-1&lt;/a&gt;, Java EE multitiered applications are generally considered 
	to be three-tiered applications because they are distributed over three 
	locations: client machines, the Java EE server machine, and the database or 
	legacy machines at the back end. Three-tiered applications that run in this way 
	extend the standard two-tiered client and server model by placing a 
	multithreaded application server between the client application and back-end 
	storage.&lt;/p&gt;
&lt;a name="bnaaz"&gt;&lt;/a&gt;
&lt;h6&gt;Figure 1-1 Multitiered Applications&lt;/h6&gt;
&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/overview-multitieredApplications.gif"
	alt="Diagram of multitiered application structure, including client tier, web tier, business tier, and EIS tier."&gt;
&lt;a name="bnaba"&gt;&lt;/a&gt;
&lt;h4&gt;Security&lt;/h4&gt;
&lt;p&gt;While other enterprise application models require platform-specific security 
	measures in each application, the Java EE security environment enables security 
	constraints to be defined at deployment time. The Java EE platform makes 
	applications portable to a wide variety of security implementations by 
	shielding application developers from the complexity of implementing security 
	features.&lt;/p&gt;
&lt;p&gt;The Java EE platform provides standard declarative access control rules that are 
	defined by the developer and interpreted when the application is deployed on 
	the server. Java EE also provides standard login mechanisms so application 
	developers do not have to implement these mechanisms in their applications. The 
	same application works in a variety of different security environments without 
	changing the source code.&lt;/p&gt;
&lt;a name="bnabb"&gt;&lt;/a&gt;
&lt;h4&gt;Java EE Components&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-6"&gt;&lt;/a&gt;&lt;a name="indexterm-7"&gt;&lt;/a&gt;Java EE applications are 
	made up of components. A Java EE component is a self-contained functional 
	software unit that is assembled into a Java EE application with its related 
	classes and files and that communicates with other components.
&lt;/p&gt;
&lt;p&gt;The Java EE specification defines the following Java EE components:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;Application clients and applets are components that run on the client.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Java Servlet, JavaServer Faces, and JavaServer Pages&lt;sup&gt;TM&lt;/sup&gt; (JSP&lt;sup&gt;TM&lt;/sup&gt;) 
			technology components are web components that run on the server.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Enterprise JavaBeans&lt;sup&gt;TM&lt;/sup&gt; (EJB&lt;sup&gt;TM&lt;/sup&gt;) components (enterprise 
			beans) are business components that run on the server.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Java EE components are written in the Java programming language and are compiled 
	in the same way as any program in the language. The difference between Java EE 
	components and “standard” Java classes is that Java EE components are assembled 
	into a Java EE application, are verified to be well formed and in compliance 
	with the Java EE specification, and are deployed to production, where they are 
	run and managed by the Java EE server.&lt;/p&gt;
&lt;a name="bnabc"&gt;&lt;/a&gt;
&lt;h4&gt;Java EE Clients&lt;/h4&gt;
&lt;a name="indexterm-8"&gt;&lt;/a&gt;
&lt;p&gt;A Java EE client can be a web client or an application client.&lt;/p&gt;
&lt;a name="bnabd"&gt;&lt;/a&gt;
&lt;h5&gt;Web Clients&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-9"&gt;&lt;/a&gt;&lt;a name="indexterm-10"&gt;&lt;/a&gt;A &lt;b&gt;web client&lt;/b&gt; consists 
	of two parts: (1) dynamic web pages containing various types of markup language 
	(HTML, XML, and so on), which are generated by web components running in the 
	web tier, and (2) a web browser, which renders the pages received from the 
	server.&lt;/p&gt;
&lt;p&gt;A web client is sometimes called a thin client. Thin clients usually do not 
	query databases, execute complex business rules, or connect to legacy 
	applications. When you use a thin client, such heavyweight operations are 
	off-loaded to enterprise beans executing on the Java EE server, where they can 
	leverage the security, speed, services, and reliability of Java EE server-side 
	technologies.&lt;/p&gt;
&lt;a name="bnabe"&gt;&lt;/a&gt;
&lt;h5&gt;Applets&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-11"&gt;&lt;/a&gt;A web page received from the web tier can include an 
	embedded applet. An &lt;b&gt;applet&lt;/b&gt; is a small client application written in the 
	Java programming language that executes in the Java virtual machine installed 
	in the web browser. However, client systems will likely need the Java Plug-in 
	and possibly a security policy file for the applet to successfully execute in 
	the web browser.&lt;/p&gt;
&lt;p&gt;Web components are the preferred API for creating a web client program because 
	no plug-ins or security policy files are needed on the client systems. Also, 
	web components enable cleaner and more modular application design because they 
	provide a way to separate applications programming from web page design. 
	Personnel involved in web page design thus do not need to understand Java 
	programming language syntax to do their jobs.&lt;/p&gt;
&lt;a name="bnabf"&gt;&lt;/a&gt;
&lt;h5&gt;Application Clients&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-12"&gt;&lt;/a&gt;&lt;a name="indexterm-13"&gt;&lt;/a&gt;&lt;a name="indexterm-14"&gt;&lt;/a&gt;An
	&lt;b&gt;application client&lt;/b&gt; runs on a client machine and provides a way for users 
	to handle tasks that require a richer user interface than can be provided by a 
	markup language. It typically has a graphical user interface (GUI) created from 
	the Swing or the Abstract Window Toolkit (AWT) API, but a command-line 
	interface is certainly possible.&lt;/p&gt;
&lt;p&gt;Application clients directly access enterprise beans running in the business 
	tier. However, if application requirements warrant it, an application client 
	can open an HTTP connection to establish communication with a servlet running 
	in the web tier. Application clients written in languages other than Java can 
	interact with Java EE 5 servers, enabling the Java EE 5 platform to 
	interoperate with legacy systems, clients, and non-Java languages.&lt;/p&gt;
&lt;a name="bnabg"&gt;&lt;/a&gt;
&lt;h5&gt;The JavaBeans&lt;sup&gt;TM&lt;/sup&gt; Component Architecture&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-15"&gt;&lt;/a&gt;The server and client tiers might also include 
	components based on the JavaBeans component architecture (JavaBeans components) 
	to manage the data flow between an application client or applet and components 
	running on the Java EE server, or between server components and a database. 
	JavaBeans components are not considered Java EE components by the Java EE 
	specification.&lt;/p&gt;
&lt;p&gt;JavaBeans components have properties and have &lt;tt&gt;get&lt;/tt&gt; and &lt;tt&gt;set&lt;/tt&gt; methods 
	for accessing the properties. JavaBeans components used in this way are 
	typically simple in design and implementation but should conform to the naming 
	and design conventions outlined in the JavaBeans component architecture.&lt;/p&gt;
&lt;a name="bnabh"&gt;&lt;/a&gt;
&lt;h5&gt;Java EE Server Communications&lt;/h5&gt;
&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaay.html#bnabi"&gt;Figure 1-2&lt;/a&gt;
	shows the various elements that can make up the client tier. The client 
	communicates with the business tier running on the Java EE server either 
	directly or, as in the case of a client running in a browser, by going through 
	JSP pages or servlets running in the web tier.&lt;/p&gt;
&lt;a name="bnabi"&gt;&lt;/a&gt;
&lt;h6&gt;Figure 1-2 Server Communication&lt;/h6&gt;
&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/overview-serverCommunications.gif"
	alt="Diagram of client-server communication. Application clients access the business tier directly. Browsers, web pages, and applets access the web tier."&gt;&lt;p&gt;&lt;a name="indexterm-16"&gt;&lt;/a&gt;Your 
	Java EE application uses a thin browser-based client or thick application 
	client. In deciding which one to use, you should be aware of the trade-offs 
	between keeping functionality on the client and close to the user (thick 
	client) and off-loading as much functionality as possible to the server (thin 
	client). The more functionality you off-load to the server, the easier it is to 
	distribute, deploy, and manage the application; however, keeping more 
	functionality on the client can make for a better perceived user experience.&lt;/p&gt;
&lt;a name="bnabj"&gt;&lt;/a&gt;
&lt;h4&gt;Web Components&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-17"&gt;&lt;/a&gt;&lt;a name="indexterm-18"&gt;&lt;/a&gt;Java EE web components are 
	either servlets or pages created using JSP technology (JSP pages) and/or 
	JavaServer Faces technology. &lt;b&gt;Servlets&lt;/b&gt; are Java programming language 
	classes that dynamically process requests and construct responses. &lt;b&gt;JSP pages&lt;/b&gt;
	are text-based documents that execute as servlets but allow a more natural 
	approach to creating static content. &lt;b&gt;JavaServer Faces&lt;/b&gt; technology builds 
	on servlets and JSP technology and provides a user interface component 
	framework for web applications.&lt;/p&gt;
&lt;p&gt;&lt;a name="indexterm-19"&gt;&lt;/a&gt;&lt;a name="indexterm-20"&gt;&lt;/a&gt;&lt;a name="indexterm-21"&gt;&lt;/a&gt;Static 
	HTML pages and applets are bundled with web components during application 
	assembly but are not considered web components by the Java EE specification. 
	Server-side utility classes can also be bundled with web components and, like 
	HTML pages, are not considered web components.&lt;/p&gt;
&lt;p&gt;As shown in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaay.html#bnabm"&gt;
		Figure 1-3&lt;/a&gt;, the web tier, like the client tier, might include a 
	JavaBeans component to manage the user input and send that input to enterprise 
	beans running in the business tier for processing.&lt;/p&gt;
&lt;a name="bnabm"&gt;&lt;/a&gt;
&lt;h6&gt;Figure 1-3 Web Tier and Java EE Applications&lt;/h6&gt;
&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/overview-webTier.gif"
	alt="Diagram of client-server communication showing detail of JavaBeans components and JSP pages in the web tier."&gt;
&lt;a name="bnabk"&gt;&lt;/a&gt;
&lt;h4&gt;Business Components&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-22"&gt;&lt;/a&gt;&lt;a name="indexterm-23"&gt;&lt;/a&gt;Business code, which is 
	logic that solves or meets the needs of a particular business domain such as 
	banking, retail, or finance, is handled by enterprise beans running in the 
	business tier. &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaay.html#bnabn"&gt;
		Figure 1-4&lt;/a&gt; shows how an enterprise bean receives data from client 
	programs, processes it (if necessary), and sends it to the enterprise 
	information system tier for storage. An enterprise bean also retrieves data 
	from storage, processes it (if necessary), and sends it back to the client 
	program.&lt;/p&gt;
&lt;a name="bnabn"&gt;&lt;/a&gt;
&lt;h6&gt;Figure 1-4 Business and EIS Tiers&lt;/h6&gt;
&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/overview-businessAndEisTiers.gif"
	alt="Diagram of client-server communication showing detail of entities, session beans, and message-driven beans in the business tier.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=13479781032&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Java EE Containers</title><link>http://www.softxml.com/LearnTutorial.asp?id=16785995828&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;Normally, thin-client multitiered applications are hard to write because they 
	involve many lines of intricate code to handle transaction and state 
	management, multithreading, resource pooling, and other complex low-level 
	details. The component-based and platform-independent Java EE architecture 
	makes Java EE applications easy to write because business logic is organized 
	into reusable components. In addition, the Java EE server provides underlying 
	services in the form of a container for every component type. Because you do 
	not have to develop these services yourself, you are free to concentrate on 
	solving the business problem at hand.&lt;/p&gt;
&lt;a name="bnabp"&gt;&lt;/a&gt;
&lt;h4&gt;Container Services&lt;/h4&gt;
&lt;a name="indexterm-31"&gt;&lt;/a&gt;
&lt;p&gt;&lt;b&gt;Containers&lt;/b&gt; are the interface between a component and the low-level 
	platform-specific functionality that supports the component. Before a web, 
	enterprise bean, or application client component can be executed, it must be 
	assembled into a Java EE module and deployed into its container.&lt;/p&gt;
&lt;p&gt;The assembly process involves specifying container settings for each component 
	in the Java EE application and for the Java EE application itself. Container 
	settings customize the underlying support provided by the Java EE server, 
	including services such as security, transaction management, Java Naming and 
	Directory Interface&lt;sup&gt;TM&lt;/sup&gt; (JNDI) lookups, and remote connectivity. Here 
	are some of the highlights:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;&lt;a name="indexterm-32"&gt;&lt;/a&gt;The Java EE security model lets you configure a web 
			component or enterprise bean so that system resources are accessed only by 
			authorized users.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;&lt;a name="indexterm-33"&gt;&lt;/a&gt;The Java EE transaction model lets you specify 
			relationships among methods that make up a single transaction so that all 
			methods in one transaction are treated as a single unit.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;JNDI lookup services provide a unified interface to multiple naming and 
			directory services in the enterprise so that application components can access 
			these services.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;The Java EE remote connectivity model manages low-level communications between 
			clients and enterprise beans. After an enterprise bean is created, a client 
			invokes methods on it as if it were in the same virtual machine.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a name="indexterm-34"&gt;&lt;/a&gt;Because the Java EE architecture provides 
	configurable services, application components within the same Java EE 
	application can behave differently based on where they are deployed. For 
	example, an enterprise bean can have security settings that allow it a certain 
	level of access to database data in one production environment and another 
	level of database access in another production environment.&lt;/p&gt;
&lt;p&gt;&lt;a name="indexterm-35"&gt;&lt;/a&gt;The container also manages nonconfigurable services 
	such as enterprise bean and servlet life cycles, database connection resource 
	pooling, data persistence, and access to the Java EE platform APIs (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnacj.html"&gt;
		Java EE 5 APIs&lt;/a&gt;).&lt;/p&gt;
&lt;a name="bnabq"&gt;&lt;/a&gt;
&lt;h4&gt;Container Types&lt;/h4&gt;
&lt;p&gt;The deployment process installs Java EE application components in the Java EE 
	containers as illustrated in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnabo.html#bnabr"&gt;
		Figure 1-5&lt;/a&gt;.&lt;/p&gt;
&lt;a name="bnabr"&gt;&lt;/a&gt;
&lt;h6&gt;Figure 1-5 Java EE Server and Containers&lt;/h6&gt;
&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/overview-serverAndContainers.gif"
	alt="Diagram of client-server communication showing servlets and JSP pages in the web tier and enterprise beans in the business tier."&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;&lt;a name="indexterm-36"&gt;&lt;/a&gt;&lt;b&gt;Java EE server&lt;/b&gt;: The runtime portion of a Java 
			EE product. A Java EE server provides EJB and web containers.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;&lt;a name="indexterm-37"&gt;&lt;/a&gt;&lt;b&gt;Enterprise JavaBeans (EJB) container&lt;/b&gt;: Manages 
			the execution of enterprise beans for Java EE applications. Enterprise beans 
			and their container run on the Java EE server.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;&lt;a name="indexterm-38"&gt;&lt;/a&gt;&lt;b&gt;Web container&lt;/b&gt;: Manages the execution of JSP 
			page and servlet components for Java EE applications. Web components and their 
			container run on the Java EE server.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=16785995828&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Web Services Support</title><link>http://www.softxml.com/LearnTutorial.asp?id=878627672&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;Web services are web-based enterprise applications that use open, XML-based 
	standards and transport protocols to exchange data with calling clients. The 
	Java EE platform provides the XML APIs and tools you need to quickly design, 
	develop, test, and deploy web services and clients that fully interoperate with 
	other web services and clients running on Java-based or non-Java-based 
	platforms.&lt;/p&gt;
&lt;p&gt;To write web services and clients with the Java EE XML APIs, all you do is pass 
	parameter data to the method calls and process the data returned; or for 
	document-oriented web services, you send documents containing the service data 
	back and forth. No low-level programming is needed because the XML API 
	implementations do the work of translating the application data to and from an 
	XML-based data stream that is sent over the standardized XML-based transport 
	protocols. These XML-based standards and protocols are introduced in the 
	following sections.&lt;/p&gt;
&lt;p&gt;The translation of data to a standardized XML-based data stream is what makes 
	web services and clients written with the Java EE XML APIs fully interoperable. 
	This does not necessarily mean that the data being transported includes XML 
	tags because the transported data can itself be plain text, XML data, or any 
	kind of binary data such as audio, video, maps, program files, computer-aided 
	design (CAD) documents and the like. The next section introduces XML and 
	explains how parties doing business can use XML tags and schemas to exchange 
	data in a meaningful way.&lt;/p&gt;
&lt;a name="bnabt"&gt;&lt;/a&gt;
&lt;h4&gt;XML&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-42"&gt;&lt;/a&gt;XML is a cross-platform, extensible, text-based 
	standard for representing data. When XML data is exchanged between parties, the 
	parties are free to create their own tags to describe the data, set up schemas 
	to specify which tags can be used in a particular kind of XML document, and use 
	XML stylesheets to manage the display and handling of the data.&lt;/p&gt;
&lt;p&gt;For example, a web service can use XML and a schema to produce price lists, and 
	companies that receive the price lists and schema can have their own 
	stylesheets to handle the data in a way that best suits their needs. Here are 
	examples:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;One company might put XML pricing information through a program to translate the 
			XML to HTML so that it can post the price lists to its intranet.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;A partner company might put the XML pricing information through a tool to create 
			a marketing presentation.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Another company might read the XML pricing information into an application for 
			processing.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;a name="bnabu"&gt;&lt;/a&gt;
&lt;h4&gt;SOAP Transport Protocol&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-43"&gt;&lt;/a&gt;Client requests and web service responses are 
	transmitted as Simple Object Access Protocol (SOAP) messages over HTTP to 
	enable a completely interoperable exchange between clients and web services, 
	all running on different platforms and at various locations on the Internet. 
	HTTP is a familiar request-and response standard for sending messages over the 
	Internet, and SOAP is an XML-based protocol that follows the HTTP 
	request-and-response model.&lt;/p&gt;
&lt;p&gt;The SOAP portion of a transported message handles the following:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;Defines an XML-based envelope to describe what is in the message and how to 
			process the message&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Includes XML-based encoding rules to express instances of application-defined 
			data types within the message&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Defines an XML-based convention for representing the request to the remote 
			service and the resulting response&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;a name="bnabv"&gt;&lt;/a&gt;
&lt;h4&gt;WSDL Standard Format&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-44"&gt;&lt;/a&gt;The Web Services Description Language (WSDL) is a 
	standardized XML format for describing network services. The description 
	includes the name of the service, the location of the service, and ways to 
	communicate with the service. WSDL service descriptions can be stored in UDDI 
	registries or published on the web (or both). The Sun Java System Application 
	Server Platform Edition 8 provides a tool for generating the WSDL specification 
	of a web service that uses remote procedure calls to communicate with clients.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=878627672&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Java EE Application Assembly and Deployment</title><link>http://www.softxml.com/LearnTutorial.asp?id=3529601986&amp;f=javatme&amp;fo=tutorials</link><description>A Java EE application is packaged into one or more standard units for deployment to any Java EE platform-compliant system.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=3529601986&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Packaging Applications</title><link>http://www.softxml.com/LearnTutorial.asp?id=24004234340&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;A Java EE application is delivered in an Enterprise Archive (EAR) file, a
standard Java Archive (JAR) file with an &lt;tt&gt;.ear&lt;/tt&gt; extension. Using EAR files and modules
makes it possible to assemble a number of different Java EE applications using
some of the same components. No extra coding is needed; it is
only a matter of assembling (or packaging) various Java EE modules into Java
EE EAR files.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-48"&gt;&lt;/a&gt;An EAR file (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaby.html#bnabz"&gt;Figure 1-6&lt;/a&gt;) contains Java EE modules and deployment descriptors. A &lt;b&gt;deployment descriptor&lt;/b&gt;
is an XML document with an &lt;tt&gt;.xml&lt;/tt&gt; extension that describes the deployment settings of
an application, a module, or a component. Because deployment descriptor information is declarative,
it can be changed without the need to modify the source code. At
runtime, the Java EE server reads the deployment descriptor and acts upon the
application, module, or component accordingly.&lt;/p&gt;&lt;a name="bnabz"&gt;&lt;/a&gt;&lt;h6&gt;Figure 1-6 EAR File Structure&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/overview-applicationModule.gif" alt="Diagram of EAR file structure. META-INF and web, application client, EJB, and resource adapter modules are under the assembly root."&gt;&lt;p&gt;&lt;a name="indexterm-49"&gt;&lt;/a&gt;&lt;a name="indexterm-50"&gt;&lt;/a&gt;There are two types of deployment descriptors: Java EE and runtime. A &lt;b&gt;Java EE deployment descriptor&lt;/b&gt;
is defined by a Java EE specification and can be used to configure
deployment settings on any Java EE-compliant implementation. A &lt;b&gt;runtime deployment descriptor&lt;/b&gt; is used to configure
Java EE implementation-specific parameters. For example, the Sun Java System Application Server Platform
Edition 9 runtime deployment descriptor contains information such as the context root of
a web application, the mapping of portable names of an application’s resources to the
server’s resources, and Application Server implementation-specific parameters, such as caching directives. The Application
Server runtime deployment descriptors are named &lt;tt&gt;sun-&lt;/tt&gt;&lt;i&gt;moduleType&lt;/i&gt;&lt;tt&gt;.xml&lt;/tt&gt; and are located in the same &lt;tt&gt;META-INF&lt;/tt&gt;
directory as the Java EE deployment descriptor.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-51"&gt;&lt;/a&gt;A &lt;b&gt;Java EE module&lt;/b&gt; consists of one or more Java EE components for the
same container type and one component deployment descriptor of that type. An enterprise bean
module deployment descriptor, for example, declares transaction attributes and security authorizations for an
enterprise bean. A Java EE module without an application deployment descriptor can be
deployed as a &lt;b&gt;stand-alone&lt;/b&gt; module. &lt;/p&gt;&lt;p&gt;The four types of Java EE modules are as follows:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-52"&gt;&lt;/a&gt;EJB modules, which contain class
files for enterprise beans and an EJB deployment descriptor. EJB
modules are packaged as JAR files with a &lt;tt&gt;.jar&lt;/tt&gt; extension.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-53"&gt;&lt;/a&gt;&lt;a name="indexterm-54"&gt;&lt;/a&gt;Web
modules, which contain servlet class files, JSP files, supporting class
files, GIF and HTML files, and a web application deployment descriptor.
Web modules are packaged as JAR files with a &lt;tt&gt;.war&lt;/tt&gt; (Web ARchive) extension.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-55"&gt;&lt;/a&gt;Application client modules, which
contain class files and an application client deployment descriptor.
Application client modules are packaged as JAR files with a &lt;tt&gt;.jar&lt;/tt&gt; extension.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=24004234340&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Development Roles</title><link>http://www.softxml.com/LearnTutorial.asp?id=32612322179&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;Reusable modules make it possible to divide the application development and deployment process
into distinct roles so that different people or companies can perform different parts
of the process.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-59"&gt;&lt;/a&gt;The first two roles involve purchasing and installing the Java EE product and
tools. After software is purchased and installed, Java EE components can be developed
by application component providers, assembled by application assemblers, and deployed by application deployers.
In a large organization, each of these roles might be executed by different
individuals or teams. This division of labor works because each of the earlier
roles outputs a portable file that is the input for a subsequent role.
For example, in the application component development phase, an enterprise bean software developer
delivers EJB JAR files. In the application assembly role, another developer combines these EJB
JAR files into a Java EE application and saves it in an
EAR file. In the application deployment role, a system administrator at the customer site
uses the EAR file to install the Java EE application into a
Java EE server.&lt;/p&gt;&lt;p&gt;The different roles are not always executed by different people. If you work
for a small company, for example, or if you are prototyping a
sample application, you might perform the tasks in every phase.&lt;/p&gt;

&lt;a name="bnacb"&gt;&lt;/a&gt;&lt;h4&gt;Java EE Product Provider&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-60"&gt;&lt;/a&gt;The Java EE product provider is the company that designs and makes available
for purchase the Java EE platform APIs, and other features defined in the
Java EE specification. Product providers are typically application server vendors who implement the
Java EE platform according to the Java EE 5 Platform specification.&lt;/p&gt;

&lt;a name="bnacc"&gt;&lt;/a&gt;&lt;h4&gt;Tool Provider&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-61"&gt;&lt;/a&gt;The tool provider is the company or person who creates development, assembly, and
packaging tools used by component providers, assemblers, and deployers.&lt;/p&gt;

&lt;a name="bnacd"&gt;&lt;/a&gt;&lt;h4&gt;Application Component Provider&lt;/h4&gt;
&lt;p&gt;The application component provider is the company or person who creates web components,
enterprise beans, applets, or application clients for use in Java EE applications.&lt;/p&gt;

&lt;a name="bnace"&gt;&lt;/a&gt;&lt;h5&gt;Enterprise Bean Developer&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-62"&gt;&lt;/a&gt;An enterprise bean developer performs the following tasks to deliver an EJB JAR
file that contains one or more enterprise beans:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Writes and compiles the source code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Specifies the deployment descriptor&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Packages the &lt;tt&gt;.class&lt;/tt&gt; files and deployment descriptor into the EJB JAR file&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;


&lt;a name="bnacf"&gt;&lt;/a&gt;&lt;h5&gt;Web Component Developer&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-63"&gt;&lt;/a&gt;A web component developer performs the following tasks to deliver a WAR file
containing one or more web components:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Writes and compiles servlet source code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Writes JSP, JavaServer Faces, and HTML files&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Specifies the deployment descriptor&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Packages the &lt;tt&gt;.class&lt;/tt&gt;, &lt;tt&gt;.jsp&lt;/tt&gt;, and&lt;tt&gt;.html&lt;/tt&gt; files and deployment descriptor into the WAR file&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;


&lt;a name="bnacg"&gt;&lt;/a&gt;&lt;h5&gt;Application Client Developer&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-64"&gt;&lt;/a&gt;An application client developer performs the following tasks to deliver a JAR file
containing the application client:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Writes and compiles the source code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Specifies the deployment descriptor for the client&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Packages the &lt;tt&gt;.class&lt;/tt&gt; files and deployment descriptor into the JAR file&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;


&lt;a name="bnach"&gt;&lt;/a&gt;&lt;h4&gt;Application Assembler&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-65"&gt;&lt;/a&gt;The application assembler is the company or person who receives application modules from
component providers and assembles them into a Java EE application EAR file. The
assembler or deployer can edit the deployment descriptor directly or can use tools
that correctly add XML tags according to interactive selections. &lt;/p&gt;&lt;p&gt;A software developer performs the following tasks to deliver an EAR file containing
the Java EE application:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Assembles EJB JAR and WAR files created in the previous phases into a Java EE application (EAR) file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Specifies the deployment descriptor for the Java EE application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verifies that the contents of the EAR file are well formed and comply with the Java EE specification&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;


&lt;a name="bnaci"&gt;&lt;/a&gt;&lt;h4&gt;Application Deployer and Administrator&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-66"&gt;&lt;/a&gt;The application deployer and administrator is the company or person who configures and
deploys the Java EE application, administers the computing and networking infrastructure where Java EE
applications run, and oversees the runtime environment. Duties include such things as setting
transaction controls and security attributes and specifying connections to databases.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-67"&gt;&lt;/a&gt;During configuration, the deployer follows instructions supplied by the application component provider to resolve
external dependencies, specify security settings, and assign transaction attributes. During installation, the deployer
moves the application components to the server and generates the container-specific classes and
interfaces.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=32612322179&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Java EE 5 APIs</title><link>http://www.softxml.com/LearnTutorial.asp?id=25146119571&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;&lt;a name="indexterm-68"&gt;&lt;/a&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnacj.html#bnack"&gt;Figure 
		1-7&lt;/a&gt; illustrates the availability of the Java EE 5 platform APIs in each 
	Java EE container type. The following sections give a brief summary of the 
	technologies required by the Java EE platform, and the APIs used in Java EE 
	applications.&lt;/p&gt;
&lt;a name="bnack"&gt;&lt;/a&gt;
&lt;h6&gt;Figure 1-7 Java EE Platform APIs&lt;/h6&gt;
&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/overview-j2eeArchitecture.gif"
	alt="Diagram of Java EE Platform APIs for the applet, web, EJB, and application client containers."&gt;
&lt;a name="bnacl"&gt;&lt;/a&gt;
&lt;h4&gt;Enterprise JavaBeans Technology&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-69"&gt;&lt;/a&gt;An Enterprise JavaBeans&lt;sup&gt;TM&lt;/sup&gt; (EJB) component, 
	or &lt;b&gt;enterprise bean&lt;/b&gt;, is a body of code having fields and methods to 
	implement modules of business logic. You can think of an enterprise bean as a 
	building block that can be used alone or with other enterprise beans to execute 
	business logic on the Java EE server.&lt;/p&gt;
&lt;p&gt;&lt;a name="indexterm-70"&gt;&lt;/a&gt;&lt;a name="indexterm-71"&gt;&lt;/a&gt;There are two kinds of 
	enterprise beans: session beans and message-driven beans. A &lt;b&gt;session bean&lt;/b&gt; 
	represents a transient conversation with a client. When the client finishes 
	executing, the session bean and its data are gone. A &lt;b&gt;message-driven bean&lt;/b&gt; 
	combines features of a session bean and a message listener, allowing a business 
	component to receive messages asynchronously. Commonly, these are Java Message 
	Service (JMS) messages.&lt;/p&gt;
&lt;p&gt;In Java EE 5, entity beans have been replaced by Java persistence API entities. 
	An entity represents persistent data stored in one row of a database table. If 
	the client terminates, or if the server shuts down, the persistence manager 
	ensures that the entity data is saved.&lt;/p&gt;
&lt;a name="bnacm"&gt;&lt;/a&gt;
&lt;h4&gt;Java Servlet Technology&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-72"&gt;&lt;/a&gt;&lt;a name="indexterm-73"&gt;&lt;/a&gt;Java servlet technology 
	lets you define HTTP-specific servlet classes. A servlet class extends the 
	capabilities of servers that host applications that are accessed by way of a 
	request-response programming model. Although servlets can respond to any type 
	of request, they are commonly used to extend the applications hosted by web 
	servers.&lt;/p&gt;
&lt;a name="bnacn"&gt;&lt;/a&gt;
&lt;h4&gt;JavaServer Pages Technology&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-74"&gt;&lt;/a&gt;&lt;a name="indexterm-75"&gt;&lt;/a&gt;JavaServer Pages&lt;sup&gt;TM&lt;/sup&gt;
	(JSP) technology lets you put snippets of servlet code directly into a 
	text-based document. A JSP page is a text-based document that contains two 
	types of text: static data (which can be expressed in any text-based format 
	such as HTML, WML, and XML) and JSP elements, which determine how the page 
	constructs dynamic content.&lt;/p&gt;
&lt;a name="bnaco"&gt;&lt;/a&gt;
&lt;h4&gt;JavaServer Pages Standard Tag Library&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-76"&gt;&lt;/a&gt;&lt;a name="indexterm-77"&gt;&lt;/a&gt;The JavaServer Pages 
	Standard Tag Library (JSTL) encapsulates core functionality common to many JSP 
	applications. Instead of mixing tags from numerous vendors in your JSP 
	applications, you employ a single, standard set of tags. This standardization 
	allows you to deploy your applications on any JSP container that supports JSTL 
	and makes it more likely that the implementation of the tags is optimized.&lt;/p&gt;
&lt;p&gt;JSTL has iterator and conditional tags for handling flow control, tags for 
	manipulating XML documents, internationalization tags, tags for accessing 
	databases using SQL, and commonly used functions.&lt;/p&gt;
&lt;a name="bnacp"&gt;&lt;/a&gt;
&lt;h4&gt;JavaServer Faces&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-78"&gt;&lt;/a&gt;JavaServer Faces technology is a user interface 
	framework for building web applications. The main components of JavaServer 
	Faces technology are as follows:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;A GUI component framework.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;A flexible model for rendering components in different kinds of HTML or 
			different markup languages and technologies. A &lt;tt&gt;Renderer&lt;/tt&gt; object 
			generates the markup to render the component and converts the data stored in a 
			model object to types that can be represented in a view.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;A standard &lt;tt&gt;RenderKit&lt;/tt&gt; for generating HTML/4.01 markup.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The following features support the GUI components:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;Input validation&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Event handling&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Data conversion between model objects and components&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Managed model object creation&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Page navigation configuration&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All this functionality is available using standard Java APIs and XML-based 
	configuration files.&lt;/p&gt;
&lt;a name="bnacq"&gt;&lt;/a&gt;
&lt;h4&gt;Java Message Service API&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-79"&gt;&lt;/a&gt;The Java Message Service (JMS) API is a messaging 
	standard that allows Java EE application components to create, send, receive, 
	and read messages. It enables distributed communication that is loosely 
	coupled, reliable, and asynchronous.&lt;/p&gt;
&lt;a name="bnacr"&gt;&lt;/a&gt;
&lt;h4&gt;Java Transaction API&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-80"&gt;&lt;/a&gt;&lt;a name="indexterm-81"&gt;&lt;/a&gt;The Java Transaction API 
	(JTA) provides a standard interface for demarcating transactions. The Java EE 
	architecture provides a default auto commit to handle transaction commits and 
	rollbacks. An &lt;b&gt;auto commit&lt;/b&gt; means that any other applications that are 
	viewing data will see the updated data after each database read or write 
	operation. However, if your application performs two separate database access 
	operations that depend on each other, you will want to use the JTA API to 
	demarcate where the entire transaction, including both operations, begins, 
	rolls back, and commits.&lt;/p&gt;
&lt;a name="bnacs"&gt;&lt;/a&gt;
&lt;h4&gt;JavaMail API&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-82"&gt;&lt;/a&gt;Java EE applications use the JavaMail&lt;sup&gt;TM&lt;/sup&gt; API 
	to send email notifications. The JavaMail API has two parts: an 
	application-level interface used by the application components to send mail, 
	and a service provider interface. The Java EE platform includes JavaMail with a 
	service provider that allows application components to send Internet mail.&lt;/p&gt;
&lt;a name="bnact"&gt;&lt;/a&gt;
&lt;h4&gt;JavaBeans Activation Framework&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-83"&gt;&lt;/a&gt;&lt;a name="indexterm-84"&gt;&lt;/a&gt;The JavaBeans Activation 
	Framework (JAF) is included because JavaMail uses it. JAF provides standard 
	services to determine the type of an arbitrary piece of data, encapsulate 
	access to it, discover the operations available on it, and create the 
	appropriate JavaBeans component to perform those operations.&lt;/p&gt;
&lt;a name="bnacu"&gt;&lt;/a&gt;
&lt;h4&gt;Java API for XML Processing&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-85"&gt;&lt;/a&gt;&lt;a name="indexterm-86"&gt;&lt;/a&gt;The Java API for XML 
	Processing (JAXP), part of the Java SE platform, supports the processing of XML 
	documents using Document Object Model (DOM), Simple API for XML (SAX), and 
	Extensible Stylesheet Language Transformations (XSLT). JAXP enables 
	applications to parse and transform XML documents independent of a particular 
	XML processing implementation.&lt;/p&gt;
&lt;p&gt;JAXP also provides namespace support, which lets you work with schemas that 
	might otherwise have naming conflicts. Designed to be flexible, JAXP lets you 
	use any XML-compliant parser or XSL processor from within your application and 
	supports the W3C schema. You can find information on the W3C schema at this 
	URL: &lt;a href="http://www.w3.org/XML/Schema"&gt;http://www.w3.org/XML/Schema&lt;/a&gt;.&lt;/p&gt;
&lt;a name="bnacv"&gt;&lt;/a&gt;
&lt;h4&gt;Java API for XML Web Services (JAX-WS)&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-87"&gt;&lt;/a&gt;&lt;a name="indexterm-88"&gt;&lt;/a&gt;The JAX-WS specification 
	provides support for web services that use the JAXB API for binding XML data to 
	Java objects. The JAX-WS specification defines client APIs for accessing web 
	services as well as techniques for implementing web service endpoints. The Web 
	Services for J2EE specification describes the deployment of JAX-WS-based 
	services and clients. The EJB and servlet specifications also describe aspects 
	of such deployment. It must be possible to deploy JAX-WS-based applications 
	using any of these deployment models.&lt;/p&gt;
&lt;p&gt;The JAX-WS specification describes the support for message handlers that can 
	process message requests and responses. In general, these message handlers 
	execute in the same container and with the same privileges and execution 
	context as the JAX-WS client or endpoint component with which they are 
	associated. These message handlers have access to the same JNDI &lt;tt&gt;java:comp/env&lt;/tt&gt;
	namespace as their associated component. Custom serializers and deserializers, 
	if supported, are treated in the same way as message handlers.&lt;/p&gt;
&lt;a name="bnacw"&gt;&lt;/a&gt;
&lt;h4&gt;Java Architecture for XML Binding (JAXB)&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-89"&gt;&lt;/a&gt;&lt;a name="indexterm-90"&gt;&lt;/a&gt;The Java Architecture for 
	XML Binding (JAXB) provides a convenient way to bind an XML schema to a 
	representation in Java language programs. JAXB can be used independently or in 
	combination with JAX-WS, where it provides a standard data binding for web 
	service messages. All Java EE application client containers, web containers, 
	and EJB containers support the JAXB API.&lt;/p&gt;
&lt;a name="bnacx"&gt;&lt;/a&gt;
&lt;h4&gt;SOAP with Attachments API for Java&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-91"&gt;&lt;/a&gt;&lt;a name="indexterm-92"&gt;&lt;/a&gt;The SOAP with Attachments 
	API for Java (SAAJ) is a low-level API on which JAX-WS and JAXR depend. SAAJ 
	enables the production and consumption of messages that conform to the SOAP 1.1 
	specification and SOAP with Attachments note. Most developers do not use the 
	SAAJ API, instead using the higher-level JAX-WS API.&lt;/p&gt;
&lt;a name="bnacy"&gt;&lt;/a&gt;
&lt;h4&gt;Java API for XML Registries&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-93"&gt;&lt;/a&gt;&lt;a name="indexterm-94"&gt;&lt;/a&gt;&lt;a name="indexterm-95"&gt;&lt;/a&gt;&lt;a name="indexterm-96"&gt;&lt;/a&gt;The 
	Java API for XML Registries (JAXR) lets you access business and general-purpose 
	registries over the web. JAXR supports the ebXML Registry and Repository 
	standards and the emerging UDDI specifications. By using JAXR, developers can 
	learn a single API and gain access to both of these important registry 
	technologies.&lt;/p&gt;
&lt;p&gt;Additionally, businesses can submit material to be shared and search for 
	material that others have submitted. Standards groups have developed schemas 
	for particular kinds of XML documents; two businesses might, for example, agree 
	to use the schema for their industry’s standard purchase order form. Because 
	the schema is stored in a standard business registry, both parties can use JAXR 
	to access it.&lt;/p&gt;
&lt;a name="bnacz"&gt;&lt;/a&gt;
&lt;h4&gt;J2EE Connector Architecture&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-97"&gt;&lt;/a&gt;&lt;a name="indexterm-98"&gt;&lt;/a&gt;&lt;a name="indexterm-99"&gt;&lt;/a&gt;The 
	J2EE Connector architecture is used by tools vendors and system integrators to 
	create resource adapters that support access to enterprise information systems 
	that can be plugged in to any Java EE product. A &lt;b&gt;resource adapter&lt;/b&gt; is a 
	software component that allows Java EE application components to access and 
	interact with the underlying resource manager of the EIS. Because a resource 
	adapter is specific to its resource manager, typically there is a different 
	resource adapter for each type of database or enterprise information system.&lt;/p&gt;
&lt;p&gt;The J2EE Connector architecture also provides a performance-oriented, secure, 
	scalable, and message-based transactional integration of Java EE-based web 
	services with existing EISs that can be either synchronous or asynchronous. 
	Existing applications and EISs integrated through the J2EE Connector 
	architecture into the Java EE platform can be exposed as XML-based web services 
	by using JAX-WS and Java EE component models. Thus JAX-WS and the J2EE 
	Connector architecture are complementary technologies for enterprise 
	application integration (EAI) and end-to-end business integration.&lt;/p&gt;
&lt;a name="bnada"&gt;&lt;/a&gt;
&lt;h4&gt;Java Database Connectivity API&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-100"&gt;&lt;/a&gt;&lt;a name="indexterm-101"&gt;&lt;/a&gt;The Java Database 
	Connectivity (JDBC) API lets you invoke SQL commands from Java programming 
	language methods. You use the JDBC API in an enterprise bean when you have a 
	session bean access the database. You can also use the JDBC API from a servlet 
	or a JSP page to access the database directly without going through an 
	enterprise bean.&lt;/p&gt;
&lt;p&gt;The JDBC API has two parts: an application-level interface used by the 
	application components to access a database, and a service provider interface 
	to attach a JDBC driver to the Java EE platform.&lt;/p&gt;
&lt;a name="bnadb"&gt;&lt;/a&gt;
&lt;h4&gt;Java Persistence API&lt;/h4&gt;
&lt;p&gt;The Java Persistence API is a Java standards-based solution for persistence. 
	Persistence uses an object-relational mapping approach to bridge the gap 
	between an object oriented model and a relational database. Java Persistence 
	consists of three areas:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;The Java Persistence API&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;The query language&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Object/relational mapping metadata&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;a name="bnadc"&gt;&lt;/a&gt;
&lt;h4&gt;Java Naming and Directory Interface&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-102"&gt;&lt;/a&gt;&lt;a name="indexterm-103"&gt;&lt;/a&gt;&lt;a name="indexterm-104"&gt;&lt;/a&gt;&lt;a name="indexterm-105"&gt;&lt;/a&gt;&lt;a name="indexterm-106"&gt;&lt;/a&gt;&lt;a name="indexterm-107"&gt;&lt;/a&gt;&lt;a name="indexterm-108"&gt;&lt;/a&gt;The 
	Java Naming and Directory Interface&lt;sup&gt;TM&lt;/sup&gt; (JNDI) provides naming and 
	directory functionality, enabling applications to access multiple naming and 
	directory services, including existing naming and directory services such as 
	LDAP, NDS, DNS, and NIS. It provides applications with methods for performing 
	standard directory operations, such as associating attributes with objects and 
	searching for objects using their attributes. Using JNDI, a Java EE application 
	can store and retrieve any type of named Java object, allowing Java EE 
	applications to coexist with many legacy applications and systems.&lt;/p&gt;
&lt;p&gt;&lt;a name="indexterm-109"&gt;&lt;/a&gt;&lt;a name="indexterm-110"&gt;&lt;/a&gt;Java EE naming services 
	provide application clients, enterprise beans, and web components with access 
	to a JNDI naming environment. A &lt;b&gt;naming environment&lt;/b&gt; allows a component to 
	be customized without the need to access or change the component’s source code. 
	A container implements the component’s environment and provides it to the 
	component as a JNDI &lt;b&gt;naming context&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name="indexterm-111"&gt;&lt;/a&gt;&lt;a name="indexterm-112"&gt;&lt;/a&gt;A Java EE component can 
	locate its environment naming context using JNDI interfaces. A component can 
	create a &lt;tt&gt;javax.naming.InitialContext&lt;/tt&gt; object and looks up the 
	environment naming context in &lt;tt&gt;InitialContext&lt;/tt&gt; under the name &lt;tt&gt;java:comp/env&lt;/tt&gt;. 
	A component’s naming environment is stored directly in the environment naming 
	context or in any of its direct or indirect subcontexts.&lt;/p&gt;
&lt;p&gt;&lt;a name="indexterm-113"&gt;&lt;/a&gt;&lt;a name="indexterm-114"&gt;&lt;/a&gt;&lt;a name="indexterm-115"&gt;&lt;/a&gt;A 
	Java EE component can access named system-provided and user-defined objects. 
	The names of system-provided objects, such as JTA &lt;tt&gt;UserTransaction&lt;/tt&gt; objects, 
	are stored in the environment naming context, &lt;tt&gt;java:comp/en&lt;/tt&gt;v. The Java 
	EE platform allows a component to name user-defined objects, such as enterprise 
	beans, environment entries, JDBC &lt;tt&gt;DataSource&lt;/tt&gt; objects, and message 
	connections. An object should be named within a subcontext of the naming 
	environment according to the type of the object. For example, enterprise beans 
	are named within the subcontext &lt;tt&gt;java:comp/env/ejb&lt;/tt&gt;, and JDBC &lt;tt&gt;DataSource&lt;/tt&gt;
	references in the subcontext &lt;tt&gt;java:comp/env/jdbc&lt;/tt&gt;.&lt;/p&gt;
&lt;a name="bnadd"&gt;&lt;/a&gt;
&lt;h4&gt;Java Authentication and Authorization Service&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-116"&gt;&lt;/a&gt;&lt;a name="indexterm-117"&gt;&lt;/a&gt;The Java Authentication 
	and Authorization Service (JAAS) provides a way for a Java EE application to 
	authenticate and authorize a specific user or group of users to run it.&lt;/p&gt;
&lt;p&gt;JAAS is a Java programming language version of the standard Pluggable 
	Authentication Module (PAM) framework, which extends the Java Platform security 
	architecture to support user-based authorization.&lt;/p&gt;
&lt;a name="bnade"&gt;&lt;/a&gt;
&lt;h4&gt;Simplified Systems Integration&lt;/h4&gt;
&lt;p&gt;The Java EE platform is a platform-independent, full systems integration 
	solution that creates an open marketplace in which every vendor can sell to 
	every customer. Such a marketplace encourages vendors to compete, not by trying 
	to lock customers into their technologies but instead by trying to outdo each 
	other in providing products and services that benefit customers, such as better 
	performance, better tools, or better customer support.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=25146119571&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Sun Java System Application Server Platform Edition 9</title><link>http://www.softxml.com/LearnTutorial.asp?id=23982087786&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;The Sun Java System Application Server Platform Edition 9 is a fully compliant 
	implementation of the Java EE 5 platform. In addition to supporting all the 
	APIs described in the previous sections, the Application Server includes a 
	number of Java EE tools that are not part of the Java EE 5 platform but are 
	provided as a convenience to the developer.&lt;/p&gt;
&lt;p&gt;This section briefly summarizes the tools that make up the Application Server. 
	Instructions for starting and stopping the Application Server, starting the 
	Admin Console, and starting and stopping the Java DB database server are in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/gfiud.html"&gt;
		Chapter 2, Using the Tutorial Examples&lt;/a&gt;.&lt;/p&gt;
&lt;a name="bnadg"&gt;&lt;/a&gt;
&lt;h4&gt;Tools&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-120"&gt;&lt;/a&gt;The Application Server contains the tools listed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnadf.html#bnadh"&gt;
		Table 1-1&lt;/a&gt;. Basic usage information for many of the tools appears 
	throughout the tutorial. For detailed information, see the online help in the 
	GUI tools.&lt;/p&gt;
&lt;a name="bnadh"&gt;&lt;/a&gt;
&lt;h6&gt;Table 1-1 Application Server Tools&lt;/h6&gt;
&lt;table ID="Table1"&gt;
	&lt;col width="95*"&gt;
	&lt;col width="260*"&gt;
	&lt;tbody&gt;
		&lt;tr&gt;
			&lt;th align="left" valign="top"&gt;
				&lt;p&gt;Tool&lt;/p&gt;
			&lt;/th&gt;
			&lt;th align="left" valign="top"&gt;
				&lt;p&gt;Description&lt;/p&gt;
			&lt;/th&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-121"&gt;&lt;/a&gt;Admin Console&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A web-based GUI Application Server administration 
					utility. Used to stop the Application Server and manage users, resources, and 
					applications.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-122"&gt;&lt;/a&gt;&lt;tt&gt;asadmin&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A command-line Application Serveradministration 
					utility. Used to start and stop the Application Server and manage users, 
					resources, and applications.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-123"&gt;&lt;/a&gt;&lt;tt&gt;asant&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A portable command-line build tool that is an 
					extension of the Ant tool developed by the Apache Software Foundation (see &lt;a href="http://ant.apache.org/"&gt;
						http://ant.apache.org/&lt;/a&gt;). &lt;tt&gt;asant&lt;/tt&gt; contains additional tasks that 
					interact with the Application Server administration utility.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-124"&gt;&lt;/a&gt;&lt;tt&gt;appclient&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A command-line tool that launches the application 
					client container and invokes the client application packaged in the application 
					client JAR file.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-125"&gt;&lt;/a&gt;&lt;tt&gt;capture-schema&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A command-line tool to extract schema information from 
					a database, producing a schema file that the Application Server can use for 
					container-managed persistence.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-126"&gt;&lt;/a&gt;&lt;tt&gt;package-appclient&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A command-line tool to package the application client 
					container libraries and JAR files.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-127"&gt;&lt;/a&gt;Java DB database&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A copy of the Java DB database server.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-128"&gt;&lt;/a&gt;&lt;tt&gt;verifier&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A command-line tool to validate Java EE deployment 
					descriptors.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-129"&gt;&lt;/a&gt;&lt;tt&gt;xjc&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A command-line tool to transform, or bind, a source 
					XML schema to a set of JAXB content classes in the Java programming language.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-130"&gt;&lt;/a&gt;&lt;tt&gt;schemagen&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A command-line tool to create a schema file for each 
					namespace referenced in your Java classes.&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a name="indexterm-131"&gt;&lt;/a&gt;&lt;tt&gt;wsimport&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;A command-line tool to generate JAX-WS portable 
					artifacts for a given WSDL file. After generation, these artifacts can be 
					packaged in a WAR file with the WSDL and schema documents along with the 
					endpoint implementation and then deployed.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=23982087786&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Getting Started with Web Applications</title><link>http://www.softxml.com/LearnTutorial.asp?id=3254898943&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;A web application is a dynamic extension of a web or application
server. There are two types of web applications:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-163"&gt;&lt;/a&gt;&lt;b&gt;Presentation-oriented&lt;/b&gt;: A
presentation-oriented web application generates interactive web pages
containing various types of markup language (HTML, XML, and so on) and
dynamic content in response to requests. Chapters &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafd.html"&gt;Chapter 4, Java Servlet Technology&lt;/a&gt; through &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaxu.html"&gt;Chapter 15, Internationalizing and Localizing Web Applications&lt;/a&gt; cover how to develop presentation-oriented web applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-164"&gt;&lt;/a&gt;&lt;b&gt;Service-oriented&lt;/b&gt;: A
service-oriented web application implements the endpoint of a web
service.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=3254898943&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Web Applications</title><link>http://www.softxml.com/LearnTutorial.asp?id=40885547928&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;In the Java 2 platform, &lt;b&gt;web components&lt;/b&gt; provide the dynamic extension capabilities for a web
server. Web components are either Java servlets, JSP pages, or web service endpoints.
The interaction between a web client and a web application is illustrated in
&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/geysj.html#bnads"&gt;Figure 3-1&lt;/a&gt;. The client sends an HTTP request to the web server. A web
server that implements Java Servlet and JavaServer Pages technology converts the request into
an &lt;tt&gt;HTTPServletRequest&lt;/tt&gt; object. This object is delivered to a web component, which can
interact with JavaBeans components or a database to generate dynamic content. The web
component can then generate an &lt;tt&gt;HTTPServletResponse&lt;/tt&gt; or it can pass the request to
another web component. Eventually a web component generates a &lt;tt&gt;HTTPServletResponse&lt;/tt&gt; object. The web
server converts this object to an HTTP response and returns it to the
client.&lt;/p&gt;&lt;a name="bnads"&gt;&lt;/a&gt;&lt;h6&gt;Figure 3-1 Java Web Application Request Handling&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/web-requestHandling.gif" alt="Diagram of web application request handling. Clients and web components communicate using HttpServletRequest and HttpServletResponse."&gt;&lt;p&gt;&lt;b&gt;Servlets&lt;/b&gt; are Java programming language classes that dynamically process requests and construct responses.
&lt;b&gt;JSP pages&lt;/b&gt; are text-based documents that execute as servlets but allow a more natural
approach to creating static content. Although servlets and JSP pages can be used
interchangeably, each has its own strengths. Servlets are best suited for service-oriented applications (web
service endpoints are implemented as servlets) and the control functions of a presentation-oriented
application, such as dispatching requests and handling nontextual data. JSP pages are more
appropriate for generating text-based markup such as HTML, Scalable Vector Graphics (SVG), Wireless
Markup Language (WML), and XML.&lt;/p&gt;&lt;p&gt;Since the introduction of Java Servlet and JSP technology, additional Java technologies and
frameworks for building interactive web applications have been developed. &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/geysj.html#bnadt"&gt;Figure 3-2&lt;/a&gt; illustrates these technologies and
their relationships.&lt;/p&gt;&lt;a name="bnadt"&gt;&lt;/a&gt;&lt;h6&gt;Figure 3-2 Java Web Application Technologies&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/web-technologies.gif" alt="Diagram of web application technologies. JavaServer Pages, the JSP Standard Tag Library, and JavaServer Faces rest on JavaServlet technology."&gt;&lt;p&gt;Notice that Java Servlet technology is the foundation of all the web application
technologies, so you should familiarize yourself with the material in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafd.html"&gt;Chapter 4, Java Servlet Technology&lt;/a&gt; even if you
do not intend to write servlets. Each technology adds a level of
abstraction that makes web application prototyping and development faster and the web applications themselves
more maintainable, scalable, and robust.&lt;/p&gt;&lt;p&gt;Web components are supported by the services of a runtime platform called a
&lt;b&gt;web container&lt;/b&gt;. A web container provides services such as request dispatching, security, concurrency, and
life-cycle management. It also gives web components access to APIs such as naming,
transactions, and email.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-167"&gt;&lt;/a&gt;&lt;a name="indexterm-168"&gt;&lt;/a&gt;Certain aspects of web application behavior can be configured when the application is
installed, or &lt;b&gt;deployed&lt;/b&gt;, to the web container. The configuration information is maintained in
a text file in XML format called a &lt;b&gt;web application deployment descriptor&lt;/b&gt; (DD). A DD must conform
to the schema described in the &lt;a href="http://java.sun.com/products/servlet/download.html#specs"&gt;Java Servlet Specification&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;This chapter gives a brief overview of the activities involved in developing web
applications. First it summarizes the web application life cycle. Then it describes how
to package and deploy very simple web applications on the Application Server.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=40885547928&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Web Application Life Cycle</title><link>http://www.softxml.com/LearnTutorial.asp?id=24948599294&amp;f=javatme&amp;fo=tutorials</link><description>A web application consists of web components, static resource files such as images, and helper classes and libraries. The web container provides many supporting services that enhance the capabilities of web components and make them easier to develop. However, because a web application must take these services into account, the process for creating and running a web application is different from that of traditional stand-alone Java classes.

The process for creating, deploying, and executing a web application can be summarized as follows:

   1.

      Develop the web component code.
   2.

      Develop the web application deployment descriptor.
   3.

      Compile the web application components and helper classes referenced by the components.
   4.

      Optionally package the application into a deployable unit.
   5.

      Deploy the application into a web container.
   6.

      Access a URL that references the web application.

Developing web component code is covered in the later chapters. Steps 2 through 4 are expanded on in the following sections and illustrated with a Hello, World-style presentation-oriented application. This application allows a user to enter a name into an HTML form (Figure 3-3) and then displays a greeting after the name is submitted (Figure 3-4).
Figure 3-3 Greeting Form
Screen capture of Duke&amp;#8216;s greeting,
Figure 3-4 Response
Screen capture of Duke&amp;#8216;s response,

The Hello application contains two web components that generate the greeting and the response. This chapter discusses two versions of the application: a JSP version called hello1, in which the components are implemented by two JSP pages (tut-install/javaeetutorial5/examples/web/hello1/web/index.jsp and tut-install/javaeetutorial5/examples/web/hello1/web/response.jsp) and a servlet version called hello2, in which the components are implemented by two servlet classes (tut-install/javaeetutorial5/examples/web/hello2/src/servlets/GreetingServlet.java and tut-install/javaeetutorial5/examples/web/hello2/src/servlets/ResponseServlet.java).</description><guid>http://www.softxml.com/LearnTutorial.asp?id=24948599294&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Web Modules</title><link>http://www.softxml.com/LearnTutorial.asp?id=18077580542&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;In the Java EE architecture, web components and static web content files such
as images are called &lt;b&gt;web resources&lt;/b&gt;. A &lt;b&gt;web module&lt;/b&gt; is the smallest deployable and
usable unit of web resources. A Java EE web module corresponds to a
&lt;b&gt;web application&lt;/b&gt; as defined in the Java Servlet specification.&lt;/p&gt;&lt;p&gt;In addition to web components and web resources, a web module can
contain other files:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-176"&gt;&lt;/a&gt;&lt;a name="indexterm-177"&gt;&lt;/a&gt;Server-side
utility classes (database beans, shopping carts, and so on). Often
these classes conform to the JavaBeans component architecture.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Client-side classes (applets and utility classes).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;A web module has a specific structure. The top-level directory of a web
module is the &lt;b&gt;document root&lt;/b&gt; of the application. The document root is where JSP
pages, &lt;b&gt;client-side&lt;/b&gt; classes and archives, and static web resources, such as images, are
stored.&lt;/p&gt;&lt;p&gt;The document root contains a subdirectory named &lt;tt&gt;WEB-INF&lt;/tt&gt;, which contains the following files
and directories:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-178"&gt;&lt;/a&gt;&lt;tt&gt;web.xml&lt;/tt&gt;: The web application deployment descriptor&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tag library descriptor files (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnamu.html"&gt;Tag Library Descriptors&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;classes&lt;/tt&gt;: A directory that contains &lt;b&gt;server-side classes&lt;/b&gt;: servlets, utility classes, and JavaBeans components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;tags&lt;/tt&gt;: A directory that contains tag files, which are implementations of tag libraries (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnama.html#bnamb"&gt;Tag File Location&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;lib&lt;/tt&gt;: A directory that contains JAR archives of libraries called by server-side classes&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;If your web module does not contain any servlets, filter, or listener components
then it does not need a web application deployment descriptor. In other words,
if your web module only contains JSP pages and static files then you
are not required to include a &lt;tt&gt;web.xml&lt;/tt&gt; file. The &lt;tt&gt;hello1&lt;/tt&gt; example, first discussed
in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnadx.html#bnadz"&gt;Packaging Web Modules&lt;/a&gt;, contains only JSP pages and images and therefore does not include
a deployment descriptor.&lt;/p&gt;&lt;p&gt;You can also create application-specific subdirectories (that is, package directories) in either the
document root or the &lt;tt&gt;WEB-INF/classes/&lt;/tt&gt; directory.&lt;/p&gt;&lt;p&gt;A web module can be deployed as an unpacked file structure or
can be packaged in a JAR file known as a web archive (WAR)
file. Because the contents and use of WAR files differ from those of
JAR files, WAR file names use a &lt;tt&gt;.war&lt;/tt&gt; extension. The web module
just described is portable; you can deploy it into any web container that
conforms to the Java Servlet Specification.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-179"&gt;&lt;/a&gt;To deploy a WAR on the Application Server, the file must also contain
a runtime deployment descriptor. The runtime deployment descriptor is an XML file that
contains information such as the context root of the web application and the
mapping of the portable names of an application’s resources to the Application Server’s resources.
The Application Server web application runtime DD is named &lt;tt&gt;sun-web.xml&lt;/tt&gt; and is
located in the &lt;tt&gt;WEB-INF&lt;/tt&gt; directory along with the web application DD. The structure
of a web module that can be deployed on the Application Server is
shown in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnadx.html#bnady"&gt;Figure 3-5&lt;/a&gt;.&lt;/p&gt;&lt;a name="bnady"&gt;&lt;/a&gt;&lt;h6&gt;Figure 3-5 Web Module Structure&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/web-module.gif" alt="Diagram of web module structure. WEB-INF and web pages are under the root. Under WEB-INF are descriptors and the lib, classes, and tags directories."&gt;

&lt;a name="bnadz"&gt;&lt;/a&gt;&lt;h4&gt;Packaging Web Modules&lt;/h4&gt;
&lt;p&gt;A web module must be packaged into a WAR in certain deployment
scenarios and whenever you want to distribute the web module. You package a
web module into a WAR by executing the &lt;tt&gt;jar&lt;/tt&gt; command in a directory laid
out in the format of a web module, by using the Ant
utility, or by using the IDE tool of your choice. This tutorial shows
you how to use NetBeans IDE or Ant to build, package, and deploy
the sample applications.&lt;/p&gt;&lt;p&gt;To build the &lt;tt&gt;hello1&lt;/tt&gt; application with NetBeans IDE, follow these instructions:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Select File&amp;#8594;Open Project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Open Project dialog, navigate to:&lt;/p&gt;&lt;pre&gt;&lt;i&gt;tut-install&lt;/i&gt;/javaeetutorial5/examples/web/&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the &lt;tt&gt;hello1&lt;/tt&gt; folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the Open as Main Project check box.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Open Project Folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Projects tab, right-click the &lt;tt&gt;hello1&lt;/tt&gt; project and select Build Project.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;To build the &lt;tt&gt;hello1&lt;/tt&gt; application using the Ant utility, follow these steps:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;In a terminal window, go to &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/hello1/&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type &lt;tt&gt;&lt;b&gt;ant&lt;/b&gt;&lt;/tt&gt;. This command will spawn any necessary compilations, copy files to the &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/hello1/build/&lt;/tt&gt; directory, create the WAR file, and copy it to the &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/hello1/dist/&lt;/tt&gt; directory.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;


&lt;a name="bnaea"&gt;&lt;/a&gt;&lt;h4&gt;Deploying a WAR File&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-180"&gt;&lt;/a&gt;You can deploy a WAR file to the Application Server in a
few ways:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Copying the WAR into the &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;domain-dir&lt;/i&gt;&lt;tt&gt;/autodeploy/&lt;/tt&gt; directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using the Admin Console.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By running &lt;tt&gt;asadmin&lt;/tt&gt; or &lt;tt&gt;ant&lt;/tt&gt; to deploy the WAR.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using NetBeans IDE.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;All these methods are described briefly in this chapter; however, throughout the tutorial,
you will use &lt;tt&gt;ant&lt;/tt&gt; and NetBeans IDE for packaging and deploying.&lt;/p&gt;

&lt;a name="bnaeb"&gt;&lt;/a&gt;&lt;h5&gt;Setting the Context Root&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-181"&gt;&lt;/a&gt;A &lt;b&gt;context root&lt;/b&gt; identifies a web application in a Java EE server. You
specify the context root when you deploy a web module. A context root
must start with a forward slash (&lt;tt&gt;/&lt;/tt&gt;) and end with a string.&lt;/p&gt;&lt;p&gt;In a packaged web module for deployment on the Application Server, the context
root is stored in &lt;tt&gt;sun-web.xml&lt;/tt&gt;.&lt;/p&gt;&lt;p&gt;To edit the context root, do the following:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Expand your project tree in the Projects pane of NetBeans IDE.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expand the Web Pages and WEB-INF nodes of your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Double-click &lt;tt&gt;sun-web.xml&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the editor pane, click Edit As XML.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Edit the context root, which is enclosed by the &lt;tt&gt;context-root&lt;/tt&gt; element.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;


&lt;a name="bnaec"&gt;&lt;/a&gt;&lt;h5&gt;Deploying a Packaged Web Module&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-182"&gt;&lt;/a&gt;If you have deployed the &lt;tt&gt;hello1&lt;/tt&gt; application, before proceeding with this section,
undeploy the application by following one of the procedures described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnadx.html#bnaen"&gt;Undeploying Web Modules&lt;/a&gt;.&lt;/p&gt;

&lt;a name="bnaed"&gt;&lt;/a&gt;&lt;h5&gt;Deploying with the Admin Console&lt;/h5&gt;

&lt;ol&gt;&lt;li&gt;&lt;p&gt;Expand the Applications node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the Web Applications node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the Deploy button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the radio button labeled “Package file to be uploaded to the Application Server.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type the full path to the WAR file (or click on Browse to find it), and then click the OK button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Next.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type the application name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type the context root.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the Enabled box.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the Finish button.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;


&lt;a name="bnaee"&gt;&lt;/a&gt;&lt;h5&gt;Deploying with &lt;tt&gt;asadmin&lt;/tt&gt;&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-183"&gt;&lt;/a&gt;To deploy a WAR with &lt;tt&gt;asadmin&lt;/tt&gt;, open a terminal window or command prompt
and execute&lt;/p&gt;&lt;pre&gt;&lt;tt&gt;&lt;b&gt;asadmin deploy &lt;/b&gt;&lt;/tt&gt;&lt;b&gt;&lt;i&gt;full-path-to-war-file&lt;/i&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/b&gt;&lt;/pre&gt;

&lt;a name="bnaef"&gt;&lt;/a&gt;&lt;h5&gt;Deploying with Ant&lt;/h5&gt;
&lt;p&gt;To deploy a WAR with the Ant tool, open a terminal window
or command prompt in the directory where you built and packaged the WAR,
and execute&lt;/p&gt;&lt;pre&gt;&lt;tt&gt;&lt;b&gt;ant deploy&lt;/b&gt;&lt;/tt&gt;&lt;/pre&gt;

&lt;a name="bnaeg"&gt;&lt;/a&gt;&lt;h5&gt;Deploying with NetBeans IDE&lt;/h5&gt;
&lt;p&gt;To deploy a WAR with NetBeans IDE, do the following:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Select File&amp;#8594;Open Project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Open Project dialog, navigate to your project and open it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Projects tab, right-click the project and select Deploy Project.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;


&lt;a name="bnaeh"&gt;&lt;/a&gt;&lt;h4&gt;Testing Deployed Web Modules&lt;/h4&gt;
&lt;p&gt;Now that the web module is deployed, you can view it by
opening the application in a web browser. By default, the application is deployed
to host &lt;tt&gt;localhost&lt;/tt&gt; on port 8080. The context root of the web
application is &lt;tt&gt;hello1&lt;/tt&gt;.&lt;/p&gt;&lt;p&gt;To test the application, follow these steps:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Open a web browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the following URL in the web address box:&lt;/p&gt;&lt;pre&gt;http://localhost:8080/hello1&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter your name, and click Submit.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;The application should display the name you submitted as shown in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnadu.html#bnadv"&gt;Figure 3-3&lt;/a&gt;
and &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnadu.html#bnadw"&gt;Figure 3-4&lt;/a&gt;.&lt;/p&gt;

&lt;a name="bnaei"&gt;&lt;/a&gt;&lt;h4&gt;Listing Deployed Web Modules&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-184"&gt;&lt;/a&gt;The Application Server provides two ways to view the deployed web modules: the
Admin Console and the &lt;tt&gt;asadmin&lt;/tt&gt; command.&lt;/p&gt;&lt;p&gt;To use the Admin Console:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Open the URL &lt;tt&gt;http://localhost:4848/asadmin&lt;/tt&gt; in a browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expand the nodes Applications&amp;#8594;Web Applications.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Use the &lt;tt&gt;asadmin&lt;/tt&gt; command as follows:&lt;/p&gt;&lt;pre&gt;&lt;tt&gt;&lt;b&gt;asadmin list-components&lt;/b&gt;&lt;/tt&gt;&lt;/pre&gt;

&lt;a name="bnaej"&gt;&lt;/a&gt;&lt;h4&gt;Updating Web Modules&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-185"&gt;&lt;/a&gt;&lt;a name="indexterm-186"&gt;&lt;/a&gt;A typical iterative development cycle involves deploying a web module and then making
changes to the application components. To update a deployed web module, you must
do the following:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Recompile any modified classes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you have deployed a packaged web module, update any modified components in the WAR.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Redeploy the module.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reload the URL in the client.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;


&lt;a name="bnaek"&gt;&lt;/a&gt;&lt;h5&gt;Updating a Packaged Web Module&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-187"&gt;&lt;/a&gt;This section describes how to update the &lt;tt&gt;hello1&lt;/tt&gt; web module that you packaged.&lt;/p&gt;&lt;p&gt;First, change the greeting in the file &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/hello1/web/index.jsp&lt;/tt&gt; to&lt;/p&gt;&lt;pre&gt;&amp;lt;h2&amp;gt;Hi, my name is Duke. What’s yours?&amp;lt;/h2&amp;gt;&lt;/pre&gt;&lt;p&gt;To update the project in NetBeans IDE:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Right-click on the project and select Build Project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right-click on the project and select Deploy Project.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;To update the project using the Ant build tool:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Type &lt;tt&gt;&lt;b&gt;ant&lt;/b&gt;&lt;/tt&gt; to copy the modified JSP page into the &lt;tt&gt;build&lt;/tt&gt; directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type &lt;tt&gt;&lt;b&gt;ant deploy&lt;/b&gt;&lt;/tt&gt; to deploy the WAR file.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;To view the modified module, reload the URL in the browser.&lt;/p&gt;&lt;p&gt;You should see the screen in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnadx.html#bnael"&gt;Figure 3-6&lt;/a&gt; in the browser.&lt;/p&gt;&lt;a name="bnael"&gt;&lt;/a&gt;&lt;h6&gt;Figure 3-6 New Greeting&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/web-newGreeting.gif" alt="Screen capture of Duke&amp;#8216;s new greeting, " hi,="" my="" is="" duke.="" what="" s="" yours?="" includes="" a="" text="" field="" for="" your="" name="" submit="" and="" reset="" buttons.="" height="350" width="662"&gt;

&lt;a name="bnaem"&gt;&lt;/a&gt;&lt;h5&gt;Dynamic Reloading&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-188"&gt;&lt;/a&gt;If dynamic reloading is enabled, you do not have to redeploy an application
or module when you change its code or deployment descriptors. All you have
to do is copy the changed JSP or class files into the
deployment directory for the application or module. The deployment directory for a web module
named &lt;i&gt;context-root&lt;/i&gt; is &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;domain-dir&lt;/i&gt;&lt;tt&gt;/applications/j2ee-modules/&lt;/tt&gt;&lt;i&gt;context-root&lt;/i&gt;&lt;tt&gt;&lt;/tt&gt;. The server checks for changes periodically and redeploys the
application, automatically and dynamically, with the changes.&lt;/p&gt;&lt;p&gt;This capability is useful in a development environment, because it allows code changes
to be tested quickly. Dynamic reloading is not recommended for a production environment,
however, because it may degrade performance. In addition, whenever a reload is done,
the sessions at that time become invalid and the client must restart the
session.&lt;/p&gt;&lt;p&gt;To enable dynamic reloading, use the Admin Console:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Select the Applications Server node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the Advanced tab.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check the Reload Enabled box to enable dynamic reloading.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter a number of seconds in the Reload Poll Interval field to
set the interval at which applications and modules are checked for code
changes and dynamically reloaded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the Save button.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;In addition, to load new servlet files or reload deployment descriptor changes, you
must do the following:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Create an empty file named &lt;tt&gt;.reload&lt;/tt&gt; at the root of the module:&lt;/p&gt;&lt;pre&gt;&lt;i&gt;domain-dir&lt;/i&gt;/applications/j2ee-modules/&lt;i&gt;context-root&lt;/i&gt;/.reload&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Explicitly update the &lt;tt&gt;.reload&lt;/tt&gt; file’s time stamp each time you make these changes. On UNIX, execute&lt;/p&gt;&lt;pre&gt;&lt;tt&gt;&lt;b&gt;touch .reload&lt;/b&gt;&lt;/tt&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;For JSP pages, changes are reloaded automatically at a frequency set in the
Reload Poll Interval field. To disable dynamic reloading of JSP pages, set the
Reload Poll Interval field value to –1.&lt;a name="indexterm-189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;a name="bnaen"&gt;&lt;/a&gt;&lt;h4&gt;Undeploying Web Modules&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-190"&gt;&lt;/a&gt;You can undeploy web modules in four ways: you can use NetBeans
IDE, the Admin Console, the &lt;tt&gt;asadmin&lt;/tt&gt; command, or the Ant tool.&lt;/p&gt;&lt;p&gt;To use NetBeans IDE:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Ensure the Sun Java System Application Server is running.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Runtime window, expand the Sun Java System Application Server instance and the node containing the application or module.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right-click the application or module and choose Undeploy.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;To use the Admin Console:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Open the URL &lt;tt&gt;http://localhost:4848/asadmin&lt;/tt&gt; in a browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expand the Applications node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select Web Applications.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=18077580542&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Configuring Web Applications</title><link>http://www.softxml.com/LearnTutorial.asp?id=23457629470&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;Web applications are configured by means of elements contained in the web 
	application deployment descriptor.&lt;/p&gt;
&lt;p&gt;The following sections give a brief introduction to the web application features 
	you will usually want to configure. A number of security parameters can be 
	specified; these are covered in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bncas.html"&gt;
		Chapter 30, Securing Web Applications&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the following sections, examples demonstrate procedures for configuring the 
	Hello, World application. If Hello, World does not use a specific configuration 
	feature, the section gives references to other examples that illustrate how to 
	specify the deployment descriptor element.&lt;/p&gt;
&lt;a name="bnaep"&gt;&lt;/a&gt;
&lt;h4&gt;Mapping URLs to Web Components&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-192"&gt;&lt;/a&gt;When a request is received by the web container it 
	must determine which web component should handle the request. It does so by 
	mapping the URL path contained in the request to a web application and a web 
	component. A URL path contains the context root and an alias:&lt;/p&gt;
&lt;pre&gt;http://&lt;i&gt;host&lt;/i&gt;:&lt;i&gt;port&lt;/i&gt;/&lt;i&gt;context-root&lt;/i&gt;/&lt;i&gt;alias&lt;/i&gt;&lt;/pre&gt;
&lt;a name="bnaeq"&gt;&lt;/a&gt;
&lt;h5&gt;Setting the Component Alias&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-193"&gt;&lt;/a&gt;The &lt;b&gt;alias&lt;/b&gt; identifies the web component that 
	should handle a request. The alias path must start with a forward slash (&lt;tt&gt;/&lt;/tt&gt;) 
	and end with a string or a wildcard expression with an extension (for example, &lt;tt&gt;*.jsp&lt;/tt&gt;). 
	Since web containers automatically map an alias that ends with &lt;tt&gt;*.jsp&lt;/tt&gt;, 
	you do not have to specify an alias for a JSP page unless you wish to refer to 
	the page by a name other than its file name.&lt;/p&gt;
&lt;p&gt;The &lt;tt&gt;hello2&lt;/tt&gt; application has two servlets that need to be mapped in the &lt;tt&gt;web.xml&lt;/tt&gt;
	file. You can edit a web applicationfs &lt;tt&gt;web.xml&lt;/tt&gt; file in NetBeans IDE by 
	doing the following:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Select File¨Open Project.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;In the Open Project dialog, navigate to:&lt;/p&gt;
		&lt;pre&gt;&lt;i&gt;tut-install&lt;/i&gt;/javaeetutorial5/examples/web/&lt;/pre&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Select the &lt;tt&gt;hello2&lt;/tt&gt; folder.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Select the Open as Main Project check box.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click Open Project Folder.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the project tree in the Projects pane.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the Web pages node and then the WEB-INF node in the project tree.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Double-click the &lt;tt&gt;web.xml&lt;/tt&gt; file inside the WEB-INF node.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The following steps describe how to make the necessary edits to the &lt;tt&gt;web.xml&lt;/tt&gt;
	file, including how to set the display name and how to map the servlet 
	components. Because the edits are already in the file, you can just use the 
	steps to view the settings.&lt;/p&gt;
&lt;p&gt;To set the display name:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Click General at the top of the editor to open the general view.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Enter &lt;tt&gt;hello2&lt;/tt&gt; in the Display Name field.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To perform the servlet mappings:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Click Servlets at the top of the editor to open the servlets view.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click Add Servlet.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;In the Add Servlet dialog, enter &lt;tt&gt;GreetingServlet&lt;/tt&gt; in the Servlet Name 
			field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Enter &lt;tt&gt;servlets.GreetingServlet&lt;/tt&gt; in the Servlet Class field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Enter &lt;tt&gt;/greeting&lt;/tt&gt; in the URL Pattern field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click OK.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Repeat the preceding steps, except enter &lt;tt&gt;ResponseServlet&lt;/tt&gt; as the servlet 
			name, &lt;tt&gt;servlets.ResponseServlet&lt;/tt&gt; as the servlet class, and &lt;tt&gt;/response&lt;/tt&gt;
			as the URL pattern.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you are not using NetBeans IDE, you can add these settings using a text 
	editor.&lt;/p&gt;
&lt;p&gt;To package the example with NetBeans IDE, do the following:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Select File¨Open Project.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;In the Open Project dialog, navigate to:&lt;/p&gt;
		&lt;pre&gt;&lt;i&gt;tut-install&lt;/i&gt;/javaeetutorial5/examples/web/&lt;/pre&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Select the &lt;tt&gt;hello2&lt;/tt&gt; folder.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Select the Open as Main Project check box.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click Open Project Folder.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;In the Projects tab, right-click the &lt;tt&gt;hello2&lt;/tt&gt; project and select Build 
			Project.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To package the example with the Ant utility, do the following:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;In a terminal window, go to &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/hello2/&lt;/tt&gt;.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Type &lt;tt&gt;&lt;b&gt;ant&lt;/b&gt;&lt;/tt&gt;. This target will build the WAR file and copy it to the &lt;tt&gt;
			&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/hello2/dist/&lt;/tt&gt; directory.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To deploy the example using NetBeans IDE, right-click on the project in the 
	Projects pane and select Deploy Project.&lt;/p&gt;
&lt;p&gt;To deploy the example using Ant, type &lt;tt&gt;&lt;b&gt;ant deploy&lt;/b&gt;&lt;/tt&gt;. The deploy 
	target in this case gives you an incorrect URL to run the application. To run 
	the application, please use the URL shown at the end of this section.&lt;/p&gt;
&lt;p&gt;To run the application, first deploy the web module, and then open the URL &lt;tt&gt;http://localhost:8080/hello2/greeting&lt;/tt&gt;
	in a browser.&lt;/p&gt;
&lt;a name="bnaer"&gt;&lt;/a&gt;
&lt;h4&gt;Declaring Welcome Files&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-194"&gt;&lt;/a&gt;The &lt;b&gt;welcome files&lt;/b&gt; mechanism allows you to 
	specify a list of files that the web container will use for appending to a 
	request for a URL (called a &lt;b&gt;valid partial request&lt;/b&gt;) that is not mapped to 
	a web component.&lt;/p&gt;
&lt;p&gt;For example, suppose you define a welcome file &lt;tt&gt;welcome.html&lt;/tt&gt;. When a 
	client requests a URL such as &lt;tt&gt;&lt;i&gt;host&lt;/i&gt;:&lt;i&gt;port&lt;/i&gt;/&lt;i&gt;webapp&lt;/i&gt;/&lt;i&gt;directory&lt;/i&gt;&lt;/tt&gt;, 
	where &lt;i&gt;directory&lt;/i&gt; is not mapped to a servlet or JSP page, the file &lt;tt&gt;&lt;/tt&gt;
	&lt;i&gt;host&lt;/i&gt;&lt;tt&gt;:&lt;/tt&gt;&lt;i&gt;port&lt;/i&gt;&lt;tt&gt;/&lt;/tt&gt;&lt;i&gt;webapp&lt;/i&gt;&lt;tt&gt;/&lt;/tt&gt;&lt;i&gt;directory&lt;/i&gt;&lt;tt&gt;/welcome.html&lt;/tt&gt;
	is returned to the client.&lt;/p&gt;
&lt;p&gt;If a web container receives a valid partial request, the web container examines 
	the welcome file list and appends to the partial request each welcome file in 
	the order specified and checks whether a static resource or servlet in the WAR 
	is mapped to that request URL. The web container then sends the request to the 
	first resource in the WAR that matches.&lt;/p&gt;
&lt;p&gt;If no welcome file is specified, the Application Server will use a file named &lt;tt&gt;index.&lt;/tt&gt;&lt;i&gt;XXX&lt;/i&gt;&lt;tt&gt;&lt;/tt&gt;, 
	where &lt;i&gt;XXX&lt;/i&gt; can be &lt;tt&gt;html&lt;/tt&gt; or &lt;tt&gt;jsp&lt;/tt&gt;, as the default welcome 
	file. If there is no welcome file and no file named &lt;tt&gt;index.&lt;/tt&gt;&lt;i&gt;XXX&lt;/i&gt;&lt;tt&gt;&lt;/tt&gt;, 
	the Application Server returns a directory listing.&lt;/p&gt;
&lt;p&gt;To specify a welcome file in the web application deployment descriptor using 
	NetBeans IDE, do the following:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Open the project if you havenft already.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the projectfs node in the Projects pane.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the Web Pages node and then the WEB-INF node.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Double-click &lt;tt&gt;web.xml&lt;/tt&gt;.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Do one of the following, making sure that the JSP pages you specify are actually 
			included in the WAR file:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Click Pages at the top of the editor pane and enter the names of the JSP pages 
			that act as welcome files in the Welcome Files field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click XML at the top of the editor pane, specify the JSP pages using &lt;tt&gt;welcome-file&lt;/tt&gt;
			elements and include these elements inside a &lt;tt&gt;welcome-file-list&lt;/tt&gt; element. 
			The &lt;tt&gt;welcome-file&lt;/tt&gt; element defines the JSP page to be used as the 
			welcome page.&lt;/p&gt;
		&lt;p&gt;The example discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnama.html"&gt;
				Encapsulating Reusable Content Using Tag Files&lt;/a&gt; has a welcome file.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;&lt;/ol&gt; &lt;a name="bnaes"&gt;&lt;/a&gt;
&lt;h4&gt;Setting Initialization Parameters&lt;/h4&gt;
&lt;a name="indexterm-195"&gt;&lt;/a&gt;
&lt;p&gt;The web components in a web module share an object that represents their 
	application context (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagl.html"&gt;
		Accessing the Web Context&lt;/a&gt;). You can pass initialization parameters to 
	the context or to a web component.&lt;/p&gt;
&lt;p&gt;To add a context parameter using NetBeans IDE, do the following:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Open the project if you havenft already.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the projectfs node in the Projects pane.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the Web Pages node and then the WEB-INF node.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Double-click &lt;tt&gt;web.xml&lt;/tt&gt;.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click General at the top of the editor pane.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Select the Context Parameters node.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click Add.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;In the Add Context Parameter dialog, do the following:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Enter the name that specifies the context object in the Param Name field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Enter the parameter to pass to the context object in the Param Value field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click OK.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Alternatively, you can edit the XML of the &lt;tt&gt;web.xml&lt;/tt&gt; file directly by 
	clicking XML at the top of the editor pane and using the following elements to 
	add a context parameter:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;A &lt;tt&gt;param-name&lt;/tt&gt; element that specifies the context object&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;A &lt;tt&gt;param-value&lt;/tt&gt; element that specifies the parameter to pass to the 
			context object&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;A &lt;tt&gt;context-param&lt;/tt&gt; element that encloses the previous two elements&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For a sample context parameter, see the example discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahb.html"&gt;
		The Example JSP Pages&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name="indexterm-196"&gt;&lt;/a&gt;To add a web component initialization parameter 
	using NetBeans IDE, do the following:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Open the project if you havenft already.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the projectfs node in the Projects pane.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the Web Pages node and then the WEB-INF node.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Double-click &lt;tt&gt;web.xml&lt;/tt&gt;.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click Servlets at the top of the editor pane.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;After entering the servletfs name, class, and URL pattern, click the Add button 
			under the Initialization Parameters table.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;In the Add Initialization Parameter dialog:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Enter the name of the parameter in the Param Name field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Enter the parameterfs value in the Param Value Field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click OK.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Alternatively, you can edit the XML of the &lt;tt&gt;web.xml&lt;/tt&gt; file directly by 
	clicking XML at the top of the editor pane and using the following elements to 
	add a context parameter:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;A &lt;tt&gt;param-name&lt;/tt&gt; element that specifies the name of the initialization 
			parameter&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;A &lt;tt&gt;param-value&lt;/tt&gt; element that specifies the value of the initialization 
			parameter&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;An &lt;tt&gt;init-param&lt;/tt&gt; element that encloses the previous two elements&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;a name="bnaet"&gt;&lt;/a&gt;
&lt;h4&gt;Mapping Errors to Error Screens&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-197"&gt;&lt;/a&gt;&lt;a name="indexterm-198"&gt;&lt;/a&gt;&lt;a name="indexterm-199"&gt;&lt;/a&gt;&lt;a name="indexterm-200"&gt;&lt;/a&gt;When 
	an error occurs during execution of a web application, you can have the 
	application display a specific error screen according to the type of error. In 
	particular, you can specify a mapping between the status code returned in an 
	HTTP response or a Java programming language exception returned by any web 
	component (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafi.html#bnafn"&gt;
		Handling Servlet Errors&lt;/a&gt;) and any type of error screen.&lt;/p&gt;
&lt;p&gt;To set up error mappings using NetBeans IDE, do the following:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Open the project if you havenft already.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the projectfs node in the Projects pane.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the Web Pages node and then the WEB-INF node.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Double-click &lt;tt&gt;web.xml&lt;/tt&gt;.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click Pages at the top of the editor pane.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Expand the Error Pages node.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click Add.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;In the Add Error Page dialog:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		&lt;p&gt;Click Browse to locate the page that you want to act as the error page.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Enter the HTTP status code that will cause the error page to be opened in the 
			Error Code field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Enter the exception that will cause the error page to load in the Exception Type 
			field.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Click OK.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Alternatively, you can click XML at the top of the editor pane and enter the 
	error page mapping by hand using the following elements:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;An &lt;tt&gt;exception-type&lt;/tt&gt; element specifying either the exception or the HTTP 
			status code that will cause the error page to be opened.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;A &lt;tt&gt;location&lt;/tt&gt; element that specifies the name of a web resource to be 
			invoked when the status code or exception is returned. The name should have a 
			leading forward slash (&lt;tt&gt;/&lt;/tt&gt;).&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;An &lt;tt&gt;error-page&lt;/tt&gt; element that encloses the previous two elements.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can have multiple &lt;tt&gt;error-page&lt;/tt&gt; elements in your deployment 
	descriptor. Each one of the elements identifies a different error that causes 
	an error page to open. This error page can be the same for any number of &lt;tt&gt;error-page&lt;/tt&gt;
	elements.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;b&gt;Note - &lt;/b&gt;You can also define error screens for a JSP page contained in a 
	WAR. If error screens are defined for both the WAR and a JSP page, the JSP 
	pagefs error page takes precedence. See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahe.html#bnahi"&gt;
		Handling JSP Page Errors&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;For a sample error page mapping, see the example discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaff.html"&gt;
		The Example Servlets&lt;/a&gt;.&lt;/p&gt;
&lt;a name="bnaeu"&gt;&lt;/a&gt;
&lt;h4&gt;Declaring Resource References&lt;/h4&gt;
&lt;p&gt;If your web component uses objects such as enterprise beans, data sources, or 
	web services, you use Java EE annotations to inject these resources into your 
	application. Annotations eliminate a lot of the boilerplate lookup code and 
	configuration elements that previous versions of Java EE required.&lt;/p&gt;
&lt;p&gt;Although resource injection using annotations can be more convenient for the 
	developer, there are some restrictions from using it in web applications. 
	First, you can only inject resources into container-managed objects. This is 
	because a container must have control over the creation of a component so that 
	it can perform the injection into a component. As a result, you cannot inject 
	resources into objects such as simple JavaBeans components. However, JavaServer 
	Faces managed beans are managed by the container; therefore, they can accept 
	resource injections.&lt;/p&gt;
&lt;p&gt;Additionally, JSP pages cannot accept resource injections. This is because the 
	information represented by annotations must be available at deployment time, 
	but the JSP page is compiled after that; therefore, the annotation will not be 
	seen when it is needed. Those components that can accept resource injections 
	are listed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaeo.html#bnaev"&gt;
		Table 3-1&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This section describes how to use a couple of the annotations supported by a 
	servlet container to inject resources. &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnbrl.html"&gt;
		Chapter 25, Persistence in the Web Tier&lt;/a&gt; describes how web applications 
	use annotations supported by the Java Persistence API. &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bncas.html"&gt;
		Chapter 30, Securing Web Applications&lt;/a&gt; describes how to use annotations 
	to specify information about securing web applications.&lt;/p&gt;
&lt;a name="bnaev"&gt;&lt;/a&gt;
&lt;h6&gt;Table 3-1 Web Components That Accept Resource Injections&lt;/h6&gt;
&lt;table ID="Table1"&gt;
	&lt;col width="75*"&gt;
	&lt;col width="253*"&gt;
	&lt;tbody&gt;
		&lt;tr&gt;
			&lt;th align="left" valign="top"&gt;
				&lt;p&gt;Component&lt;/p&gt;
			&lt;/th&gt;
			&lt;th align="left" valign="top"&gt;
				&lt;p&gt;Interface/Class&lt;/p&gt;
			&lt;/th&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;Servlets&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;javax.servlet.Servlet&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;Servlet Filters&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;javax.servlet.ServletFilter&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;Event Listeners&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;javax.servlet.ServletContextListener&lt;/tt&gt;&lt;/p&gt;
				&lt;p&gt;&lt;tt&gt;javax.servlet.ServletContextAttributeListener&lt;/tt&gt;&lt;/p&gt;
				&lt;p&gt;&lt;tt&gt;javax.servlet.ServletRequestListener&lt;/tt&gt;&lt;/p&gt;
				&lt;p&gt;&lt;tt&gt;javax.servlet.ServletRequestAttributeListener&lt;/tt&gt;&lt;/p&gt;
				&lt;p&gt;&lt;tt&gt;javax.servlet.http.HttpSessionListener&lt;/tt&gt;&lt;/p&gt;
				&lt;p&gt;&lt;tt&gt;javax.servlet.http.HttpSessionAttributeListener&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;Taglib Listeners&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;Same as above&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;Taglib Tag Handlers&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;javax.servlet.jsp.tagext.JspTag&lt;/tt&gt;&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;Managed Beans&lt;/p&gt;
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt;&lt;p&gt;Plain Old Java Objects&lt;/p&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;a name="bnaew"&gt;&lt;/a&gt;
&lt;h5&gt;Declaring a Reference to a Resource&lt;/h5&gt;
&lt;p&gt;The &lt;tt&gt;@Resource&lt;/tt&gt; annotation is used to declare a reference to a resource 
	such as a data source, an enterprise bean, or an environment entry. This 
	annotation is equivalent to declaring a &lt;tt&gt;resource-ref&lt;/tt&gt; element in the 
	deployment descriptor.&lt;/p&gt;
&lt;p&gt;The &lt;tt&gt;@Resource&lt;/tt&gt; annotation is specified on a class, method or field. The 
	container is responsible for injecting references to resources declared by the &lt;tt&gt;@Resource&lt;/tt&gt;
	annotation and mapping it to the proper JNDI resources. In the following 
	example, the &lt;tt&gt;@Resource&lt;/tt&gt; annotation is used to inject a data source into 
	a component that needs to make a connection to the data source, as is done when 
	using JDBC technology to access a relational database:&lt;/p&gt;
&lt;pre&gt;@Resource javax.sql.DataSource catalogDS;
public getProductsByCategory() {
    // get a connection and execute the query
    Connection conn = catalogDS.getConnection();
    ..
}&lt;/pre&gt;
&lt;p&gt;The container injects this data source prior to the component being made 
	available to the application. The data source JNDI mapping is inferred from the 
	field name &lt;tt&gt;catalogDS&lt;/tt&gt; and the type, &lt;tt&gt;javax.sql.DataSource&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;If you have multiple resources that you need to inject into one component, you 
	need to use the &lt;tt&gt;@Resources&lt;/tt&gt; annotation to contain them, as shown by the 
	following example:&lt;/p&gt;
&lt;pre&gt;@Resources ({
    @Resource (name="myDB" type=java.sql.DataSource),
    @Resource(name="myMQ" type=javax.jms.ConnectionFactory)
})&lt;/pre&gt;
&lt;p&gt;The web application examples in this tutorial use the Java Persistence API to 
	access relational databases. This API does not require you to explicitly create 
	a connection to a data source. Therefore, the examples do not use the &lt;tt&gt;@Resource&lt;/tt&gt;
	annotation to inject a data source. However, this API supports the &lt;tt&gt;@PersistenceUnit&lt;/tt&gt;
	and &lt;tt&gt;@PersistenceContext&lt;/tt&gt; annotations for injecting &lt;tt&gt;EntityManagerFactory&lt;/tt&gt;
	and &lt;tt&gt;EntityManager&lt;/tt&gt; instances, respectively. &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnbrl.html"&gt;
		Chapter 25, Persistence in the Web Tier&lt;/a&gt; describes these annotations and 
	the use of the Java Persistence API in web applications.&lt;/p&gt;
&lt;a name="bnaex"&gt;&lt;/a&gt;
&lt;h5&gt;Declaring a Reference to a Web Service&lt;/h5&gt;
&lt;p&gt;The &lt;tt&gt;@WebServiceRef&lt;/tt&gt; annotation provides a reference to a web service.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=23457629470&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Accessing Databases from Web Applications</title><link>http://www.softxml.com/LearnTutorial.asp?id=13750206126&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;Data that is shared between web components and is persistent between invocations of
a web application is usually maintained in a database. To maintain a catalog
of books, the Duke’s Bookstore examples described in Chapters &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafd.html"&gt;Chapter 4, Java Servlet Technology&lt;/a&gt; through &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaxu.html"&gt;Chapter 15, Internationalizing and Localizing Web Applications&lt;/a&gt; use
the Java DB database included with the Application Server.&lt;/p&gt;&lt;p&gt;To access the data in a database, web applications use the new
Java Persistence API (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnbpz.html"&gt;Chapter 24, Introduction to the Java Persistence API&lt;/a&gt;). See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnbrl.html"&gt;Chapter 25, Persistence in the Web Tier&lt;/a&gt; to learn how the Duke’s Bookstore applications
use this API to access the book data.&lt;/p&gt;&lt;p&gt;To run the Duke’s Bookstore applications, you need to first populate the database
with the book data and create a data source in the application server.
The rest of this section explains how to perform these tasks.&lt;/p&gt;

&lt;a name="bnafa"&gt;&lt;/a&gt;&lt;h4&gt;Populating the Example Database&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-204"&gt;&lt;/a&gt;When you deploy any of the Duke’s Bookstore applications using &lt;tt&gt;&lt;b&gt;ant deploy&lt;/b&gt;&lt;/tt&gt;, the database is
automatically populated at the same time. If you want to populate the database
separately from the deploy task or are using NetBeans IDE to deploy the
application, follow these steps:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;In a terminal window, go to the &lt;tt&gt;books&lt;/tt&gt; directory or any one of the &lt;tt&gt;bookstore1&lt;/tt&gt; through &lt;tt&gt;bookstore6&lt;/tt&gt; example directories.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start the Java DB database server. For instructions, see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnadk.html"&gt;Starting and Stopping the Java DB Database Server&lt;/a&gt;. You don’t have to do this if you are using NetBeans IDE. It starts the database server automatically.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type &lt;tt&gt;&lt;b&gt;ant create-tables&lt;/b&gt;&lt;/tt&gt;. This task runs a command to read the file &lt;tt&gt;tutorial.sql&lt;/tt&gt; and execute the SQL commands contained in the file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;At the end of the processing, you should see the following output:&lt;/p&gt;&lt;pre&gt;...
[sql] 181 of 181 SQL statements executed successfully&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;When you are running &lt;tt&gt;create-tables&lt;/tt&gt;, don’t worry if you see a message that
an SQL statement failed. This usually happens the first time you run the
command because it always tries to delete an existing database table first before
it creates a new one. The first time through, there is no table
yet, of course.&lt;/p&gt;

&lt;a name="bnafb"&gt;&lt;/a&gt;&lt;h4&gt;Creating a Data Source in the Application Server&lt;/h4&gt;
&lt;p&gt;A &lt;tt&gt;DataSource&lt;/tt&gt; object has a set of properties that identify and describe the
real world data source that it represents. These properties include information such as
the location of the database server, the name of the database, the network
protocol to use to communicate with the server, and so on.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-205"&gt;&lt;/a&gt;Data sources in the Application Server implement connection pooling. To define the Duke’s
Bookstore data source, you use the installed Derby connection pool named &lt;tt&gt;DerbyPool&lt;/tt&gt;.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=13750206126&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Java Servlet Technology</title><link>http://www.softxml.com/LearnTutorial.asp?id=10315007433&amp;f=javatme&amp;fo=tutorials</link><description>As soon as the web began to be used for delivering services,
service providers recognized the need for dynamic content. Applets, one of the earliest attempts
toward this goal, focused on using the client platform to deliver dynamic user
experiences. At the same time, developers also investigated using the server platform for
this purpose.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=10315007433&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>What Is a Servlet?</title><link>http://www.softxml.com/LearnTutorial.asp?id=36295378106&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;A &lt;b&gt;servlet&lt;/b&gt; is a Java programming language class that is used to extend
the capabilities of servers that host applications accessed by means of a request-response
programming model. Although servlets can respond to any type of request, they are
commonly used to extend the applications hosted by web servers. For such applications,
Java Servlet technology defines HTTP-specific servlet classes.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-207"&gt;&lt;/a&gt;&lt;a name="indexterm-208"&gt;&lt;/a&gt;&lt;a name="indexterm-209"&gt;&lt;/a&gt;&lt;a name="indexterm-210"&gt;&lt;/a&gt;&lt;a name="indexterm-211"&gt;&lt;/a&gt;The &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/package-summary.html"&gt;javax.servlet&lt;/a&gt; and &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/package-summary.html"&gt;javax.servlet.http&lt;/a&gt; packages provide interfaces and classes for writing servlets. All
servlets must implement the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/Servlet.html"&gt;Servlet&lt;/a&gt; interface, which defines life-cycle methods. When implementing a
generic service, you can use or extend the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/GenericServlet.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=36295378106&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Servlet Life Cycle</title><link>http://www.softxml.com/LearnTutorial.asp?id=36969977117&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;The life cycle of a servlet is controlled by the container in
which the servlet has been deployed. When a request is mapped to a
servlet, the container performs the following steps.&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-214"&gt;&lt;/a&gt;If an instance of the servlet does not exist, the web container&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Loads the servlet class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creates an instance of the servlet class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initializes the servlet instance by calling the &lt;tt&gt;init&lt;/tt&gt; method. Initialization is covered in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafu.html"&gt;Initializing a Servlet&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Invokes the &lt;tt&gt;service&lt;/tt&gt; method, passing request and response objects. Service methods are discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafv.html"&gt;Writing Service Methods&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;If the container needs to remove the servlet, it finalizes the servlet by
calling the servlet’s &lt;tt&gt;destroy&lt;/tt&gt; method. Finalization is discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnags.html"&gt;Finalizing a Servlet&lt;/a&gt;.&lt;/p&gt;

&lt;a name="bnafj"&gt;&lt;/a&gt;&lt;h4&gt;Handling Servlet Life-Cycle Events&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-215"&gt;&lt;/a&gt;&lt;a name="indexterm-216"&gt;&lt;/a&gt;You can monitor and react to events in a servlet’s life cycle by
defining listener objects whose methods get invoked when life-cycle events occur. To use
these listener objects you must define and specify the listener class.&lt;/p&gt;

&lt;a name="bnafk"&gt;&lt;/a&gt;&lt;h5&gt;Defining the Listener Class&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-217"&gt;&lt;/a&gt;&lt;a name="indexterm-218"&gt;&lt;/a&gt;You define a listener class as an implementation of a listener interface. &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafi.html#bnafl"&gt;Table 4-2&lt;/a&gt;
lists the events that can be monitored and the corresponding interface that must
be implemented. When a listener method is invoked, it is passed an event
that contains information appropriate to the event. For example, the methods in the
&lt;tt&gt;HttpSessionListener&lt;/tt&gt; interface are passed an &lt;tt&gt;HttpSessionEvent&lt;/tt&gt;, which contains an &lt;tt&gt;HttpSession&lt;/tt&gt;.&lt;/p&gt;&lt;a name="bnafl"&gt;&lt;/a&gt;&lt;h6&gt;Table 4-2 Servlet Life-Cycle Events&lt;/h6&gt;&lt;table ID="Table1"&gt;&lt;col width="75*"&gt;&lt;col width="76*"&gt;&lt;col width="203*"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th align="left" valign="top"&gt;&lt;p&gt;Object&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;Event&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;Listener Interface and Event
Class&lt;/p&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td rowspan="2" align="left" valign="top"&gt;&lt;p&gt;Web context (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagl.html"&gt;Accessing the Web Context&lt;/a&gt;)&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;Initialization and destruction&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextListener.html"&gt;javax.servlet.ServletContextListener&lt;/a&gt; and&lt;/p&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextEvent.html"&gt;ServletContextEvent&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Attribute added, removed, or replaced&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextAttributeListener.html"&gt;javax.servlet.ServletContextAttributeListener&lt;/a&gt; and&lt;/p&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextAttributeEvent.html"&gt;ServletContextAttributeEvent&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td rowspan="2" align="left" valign="top"&gt;&lt;p&gt;Session
(See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagm.html"&gt;Maintaining Client State&lt;/a&gt;)&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;Creation, invalidation, activation, passivation, and timeout&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSessionListener.html"&gt;javax.servlet.http.HttpSessionListener&lt;/a&gt;, &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSessionActivationListener.html"&gt;javax.servlet.http.HttpSessionActivationListener&lt;/a&gt;, and&lt;/p&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSessionEvent.html"&gt;HttpSessionEvent&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Attribute added, removed, or
replaced&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSessionAttributeListener.html"&gt;javax.servlet.http.HttpSessionAttributeListener&lt;/a&gt; and&lt;/p&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSessionBindingEvent.html"&gt;HttpSessionBindingEvent&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td rowspan="2" align="left" valign="top"&gt;&lt;p&gt;Request&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;A servlet request has started being processed by web components&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequestListener.html"&gt;javax.servlet.ServletRequestListener&lt;/a&gt; and&lt;/p&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequestEvent.html"&gt;ServletRequestEvent&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Attribute
added, removed, or replaced&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequestAttributeListener.html"&gt;javax.servlet.ServletRequestAttributeListener&lt;/a&gt; and&lt;/p&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequestAttributeEvent.html"&gt;ServletRequestAttributeEvent&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;a name="indexterm-219"&gt;&lt;/a&gt;The &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore1/src/java/com/sun/bookstore1/listeners/ContextListener&lt;/tt&gt; class creates and removes the database access and counter objects used
in the Duke’s Bookstore application. The methods retrieve the web context object from
&lt;tt&gt;ServletContextEvent&lt;/tt&gt; and then store (and remove) the objects as servlet context attributes.&lt;/p&gt;&lt;pre&gt;import database.BookDBAO;
import javax.servlet.*;
import util.Counter;

import javax.ejb.*;
import javax.persistence.*;

public final class ContextListener
    implements ServletContextListener {
    private ServletContext context = null;

    @PersistenceUnit
    EntityManagerFactory emf;

    public void contextInitialized(ServletContextEvent event) {
        context = event.getServletContext();
        try {
            BookDBAO bookDB = new BookDBAO(emf);
            context.setAttribute("bookDB", bookDB);
        } catch (Exception ex) {
            System.out.println(
                "Couldn’t create database: " + ex.getMessage());
        }
        Counter counter = new Counter();
        context.setAttribute("hitCounter", counter);
        counter = new Counter();
        context.setAttribute("orderCounter", counter);
    }

    public void contextDestroyed(ServletContextEvent event) {
        context = event.getServletContext();
        BookDBAO bookDB = context.getAttribute("bookDB");
        bookDB.remove();
        context.removeAttribute("bookDB");
        context.removeAttribute("hitCounter");
        context.removeAttribute("orderCounter");
    }
}&lt;/pre&gt;

&lt;a name="bnafm"&gt;&lt;/a&gt;&lt;h5&gt;Specifying Event Listener Classes&lt;/h5&gt;
&lt;p&gt;You specify an event listener class using the &lt;tt&gt;listener&lt;/tt&gt; element of the deployment
descriptor. Review &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaff.html"&gt;The Example Servlets&lt;/a&gt; for information on how to specify the &lt;tt&gt;ContextListener&lt;/tt&gt; listener class.
&lt;/p&gt;&lt;p&gt;You can specify an event listener using the deployment descriptor editor of NetBeans
IDE by doing the following:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Expand your application’s project node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expand the project’s Web Pages and WEB-INF nodes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Double-click &lt;tt&gt;web.xml&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click General at the top of the &lt;tt&gt;web.xml&lt;/tt&gt; editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expand the Web Application Listeners node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Add.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Add Listener dialog, click Browse to locate the listener class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click OK.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;


&lt;a name="bnafn"&gt;&lt;/a&gt;&lt;h4&gt;Handling Servlet Errors&lt;/h4&gt;
&lt;p&gt;Any number of exceptions can occur when a servlet executes. When an exception
occurs, the web container generates a default page containing the message&lt;/p&gt;&lt;pre&gt;A Servlet Exception Has Occurred&lt;/pre&gt;&lt;p&gt;But you can also specify that the container should return a specific error
page for a given exception. Review the deployment descriptor file included with the
example to learn how to map the exceptions &lt;tt&gt;exception.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=36969977117&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Sharing Information</title><link>http://www.softxml.com/LearnTutorial.asp?id=112070226&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;Web components, like most objects, usually work with other objects to accomplish their
tasks. There are several ways they can do this. They can use private
helper objects (for example, JavaBeans components), they can share objects that are attributes
of a public scope, they can use a database, and they can invoke
other web resources. The Java Servlet technology mechanisms that allow a web component
to invoke other web resources are described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagi.html"&gt;Invoking Other Web Resources&lt;/a&gt;.&lt;/p&gt;

&lt;a name="bnafp"&gt;&lt;/a&gt;&lt;h4&gt;Using Scope Objects&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-221"&gt;&lt;/a&gt;Collaborating web components share information by means of objects that are maintained as
attributes of four scope objects. You access these attributes using the &lt;tt&gt;[get|set]Attribute&lt;/tt&gt; methods
of the class representing the scope. &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafo.html#bnafq"&gt;Table 4-3&lt;/a&gt; lists the scope objects.&lt;/p&gt;&lt;a name="bnafq"&gt;&lt;/a&gt;&lt;h6&gt;Table 4-3 Scope Objects&lt;/h6&gt;&lt;table ID="Table1"&gt;&lt;col width="55*"&gt;&lt;col width="103*"&gt;&lt;col width="195*"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th align="left" valign="top"&gt;&lt;p&gt;Scope Object&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;Class&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;Accessible From&lt;/p&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Web context&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html"&gt;javax.servlet.ServletContext&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;Web
components within a web context. See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagl.html"&gt;Accessing the Web Context&lt;/a&gt;.&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Session&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSession.html"&gt;javax.servlet.http.HttpSession&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;Web components handling a request that
belongs to the session. See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagm.html"&gt;Maintaining Client State&lt;/a&gt;.&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Request&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;subtype of &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html"&gt;javax.servlet.ServletRequest&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;Web components handling the request.&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Page&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/jsp/JspContext.html"&gt;javax.servlet.jsp.JspContext&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;The
JSP page that creates the object. See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahl.html#bnahn"&gt;Using Implicit Objects&lt;/a&gt;.&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafo.html#bnafr"&gt;Figure 4-1&lt;/a&gt; shows the scoped attributes maintained by the Duke’s Bookstore application.&lt;/p&gt;&lt;a name="bnafr"&gt;&lt;/a&gt;&lt;h6&gt;Figure 4-1 Duke’s Bookstore Scoped Attributes&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/web-scopedAttributes.gif" alt="Diagram of Duke&amp;#8216;s Bookstore scoped attributes. Session attributes are currency and cart, web context attributes are hitCounter, bookDB, orderCounter."&gt;

&lt;a name="bnafs"&gt;&lt;/a&gt;&lt;h4&gt;Controlling Concurrent Access to Shared Resources&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-222"&gt;&lt;/a&gt;In a multithreaded server, it is possible for shared resources to be accessed
concurrently. In addition to scope object attributes, shared resources include in-memory data (such
as instance or class variables) and external objects such as files, database connections, and
network connections. &lt;/p&gt;&lt;p&gt;Concurrent access can arise in several situations:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Multiple web components accessing objects stored in the web context.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multiple web components accessing objects stored in a session.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-223"&gt;&lt;/a&gt;Multiple threads within a web
component accessing instance variables. A web container will typically
create a thread to handle each request. If you want to ensure that a
servlet instance handles only one request at a time, a servlet can
implement the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/SingleThreadModel.html"&gt;SingleThreadModel&lt;/a&gt;
interface. If a servlet implements this interface, you are guaranteed
that no two threads will execute concurrently in the servlet’s service
method. A web container can implement this guarantee by synchronizing
access to a single instance of the servlet, or by maintaining a pool of
web component instances and dispatching each new request to a free
instance. This interface does not prevent synchronization problems that
result from web components accessing shared resources such as static
class variables or external objects. In addition, the Servlet 2.4
specification deprecates the &lt;tt&gt;SingleThreadModel&lt;/tt&gt; interface.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;When resources can be accessed concurrently, they can be used in an inconsistent
fashion. To prevent this, you must control the access using the synchronization techniques
described in the &lt;a href="http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html"&gt;Threads&lt;/a&gt; lesson in &lt;a href="http://java.sun.com/docs/books/tutorial/"&gt;&lt;i&gt;The Java Tutorial, Fourth Edition&lt;/i&gt;&lt;/a&gt;, by Sharon Zakhour et al. (Addison-Wesley,
2006).&lt;/p&gt;&lt;p&gt;The preceding section showed five scoped attributes shared by more than one servlet:
&lt;tt&gt;bookDB&lt;/tt&gt;, &lt;tt&gt;cart&lt;/tt&gt;, &lt;tt&gt;currency&lt;/tt&gt;, &lt;tt&gt;hitCounter&lt;/tt&gt;, and &lt;tt&gt;orderCounter&lt;/tt&gt;. The &lt;tt&gt;bookDB&lt;/tt&gt; attribute is discussed in the
next section. The cart, currency, and counters can be set and read by
multiple multithreaded servlets. To prevent these objects from being used inconsistently, access is controlled
by synchronized methods. For example, here is the &lt;tt&gt;Counter&lt;/tt&gt; class, located at &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore1/src/java/com/sun/bookstore1/util/&lt;/tt&gt;:&lt;/p&gt;&lt;pre&gt;public class Counter {
    private int counter;
    public Counter() {
        counter = 0;
    }
    public synchronized int getCounter() {
        return counter;
    }
    public synchronized int setCounter(int c) {
        counter = c;
        return counter;
    }
    public synchronized int incCounter() {
        return(++counter);
    }
}&lt;/pre&gt;

&lt;a name="bnaft"&gt;&lt;/a&gt;&lt;h4&gt;Accessing Databases&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-224"&gt;&lt;/a&gt;Data that is shared between web components and is persistent between invocations of
a web application is usually maintained by a database. Web components use the
Java Persistence API to access relational databases. The data for Duke’s Bookstore is
maintained in a database and is accessed through the database access class &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore1/src/java/com/sun/bookstore1/database/BookDBAO&lt;/tt&gt;.
For example, &lt;tt&gt;ReceiptServlet&lt;/tt&gt; invokes the &lt;tt&gt;BookDBAO.buyBooks&lt;/tt&gt; method to update the book inventory
when a user makes a purchase. The &lt;tt&gt;buyBooks&lt;/tt&gt; method invokes &lt;tt&gt;buyBook&lt;/tt&gt; for each
book contained in the shopping cart, as shown in the following code.&lt;/p&gt;&lt;pre&gt;public void buyBooks(ShoppingCart cart) throws OrderException{

    Collection items = cart.getItems();
    Iterator i = items.iterator();
    
    try {
        while (i.hasNext()) {
            ShoppingCartItem sci = (ShoppingCartItem)i.next();
            Book bd = (Book)sci.getItem();
            String id = bd.getBookId();
            int quantity = sci.getQuantity();
            buyBook(id, quantity);
        }
    } catch (Exception ex) {
        throw new OrderException("Commit failed: " +
            ex.getMessage());
     }
}

public void buyBook(String bookId, int quantity)
     throws OrderException {

    try {
        Book requestedBook = em.find(Book.class, bookId);
        
        if (requestedBook != null) {
            int inventory = requestedBook.getInventory();
            if ((inventory - quantity) &amp;gt;= 0) {
                int newInventory = inventory - quantity;
                requestedBook.setInventory(newInventory);
            } else{
                throw new OrderException("Not enough of "
                     + bookId + " in stock to complete order.");
            }
        }
    } catch (Exception ex) {
        throw new OrderException("Couldn’t purchase book: "
             + bookId + ex.getMessage());
    }
}&lt;/pre&gt;&lt;p&gt;&lt;a name="indexterm-225"&gt;&lt;/a&gt;&lt;a name="indexterm-226"&gt;&lt;/a&gt;To ensure that the order is processed in its entirety, the call to
&lt;tt&gt;buyBooks&lt;/tt&gt; is wrapped in a single transaction. In the following code, the calls
to the &lt;tt&gt;begin&lt;/tt&gt; and &lt;tt&gt;commit&lt;/tt&gt; methods of &lt;tt&gt;UserTransaction&lt;/tt&gt; mark the boundaries of the
transaction.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=112070226&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Initializing a Servlet</title><link>http://www.softxml.com/LearnTutorial.asp?id=10054506653&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;After the web container loads and instantiates the servlet class and before it 
	delivers requests from clients, the web container initializes the servlet. To 
	customize this process to allow the servlet to read persistent configuration 
	data, initialize resources, and perform any other one-time activities, you 
	override the &lt;tt&gt;init&lt;/tt&gt; method of the &lt;tt&gt;Servlet&lt;/tt&gt; interface. A servlet 
	that cannot complete its initialization process should throw &lt;tt&gt;UnavailableException&lt;/tt&gt;.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=10054506653&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Writing Service Methods</title><link>http://www.softxml.com/LearnTutorial.asp?id=14212247090&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;The service provided by a servlet is implemented in the &lt;tt&gt;service&lt;/tt&gt; method of a
&lt;tt&gt;GenericServlet&lt;/tt&gt;, in the &lt;tt&gt;do&lt;i&gt;Method&lt;/i&gt;&lt;/tt&gt; methods (where &lt;i&gt;Method&lt;/i&gt; can take the value &lt;tt&gt;Get&lt;/tt&gt;, &lt;tt&gt;Delete&lt;/tt&gt;,
&lt;tt&gt;Options&lt;/tt&gt;, &lt;tt&gt;Post&lt;/tt&gt;, &lt;tt&gt;Put&lt;/tt&gt;, or &lt;tt&gt;Trace&lt;/tt&gt;) of an &lt;tt&gt;HttpServlet&lt;/tt&gt; object, or in any other
protocol-specific methods defined by a class that implements the &lt;tt&gt;Servlet&lt;/tt&gt; interface. In the
rest of this chapter, the term &lt;b&gt;service method&lt;/b&gt; is used for any method in
a servlet class that provides a service to a client.&lt;/p&gt;&lt;p&gt;The general pattern for a service method is to extract information from the
request, access external resources, and then populate the response based on that information.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-234"&gt;&lt;/a&gt;For HTTP servlets, the correct procedure for populating the response is to first
retrieve an output stream from the response, then fill in the response headers,
and finally write any body content to the output stream. Response headers must
always be set before the response has been committed. Any attempt to set
or add headers after the response has been committed will be ignored by
the web container. The next two sections describe how to get information from
requests and generate responses.&lt;/p&gt;

&lt;a name="bnafw"&gt;&lt;/a&gt;&lt;h4&gt;Getting Information from Requests&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-235"&gt;&lt;/a&gt;&lt;a name="indexterm-236"&gt;&lt;/a&gt;&lt;a name="indexterm-237"&gt;&lt;/a&gt;&lt;a name="indexterm-238"&gt;&lt;/a&gt;A request contains data passed between a client and the servlet. All requests
implement the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html"&gt;ServletRequest&lt;/a&gt; interface. This interface defines methods for accessing the following information:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Parameters, which are typically used to convey information between clients and servlets&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Object-valued attributes, which are typically used to pass
information between the servlet container and a servlet or between
collaborating servlets&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Information about the protocol used to communicate the request and about the client and server involved in the request&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Information relevant to localization&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;a name="indexterm-239"&gt;&lt;/a&gt;For example, in &lt;tt&gt;CatalogServlet&lt;/tt&gt; the identifier of the book that a customer wishes
to purchase is included as a parameter to the request. The following code
fragment illustrates how to use the &lt;tt&gt;getParameter&lt;/tt&gt; method to extract the identifier:&lt;/p&gt;&lt;pre&gt;String bookId = request.getParameter("Add");
if (bookId != null) {
    Book book = bookDB.getBook(bookId);&lt;/pre&gt;&lt;p&gt;&lt;a name="indexterm-240"&gt;&lt;/a&gt;&lt;a name="indexterm-241"&gt;&lt;/a&gt;&lt;a name="indexterm-242"&gt;&lt;/a&gt;&lt;a name="indexterm-243"&gt;&lt;/a&gt;You can also retrieve an input stream from the request and manually parse
the data. To read character data, use the &lt;a href="http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html"&gt;BufferedReader&lt;/a&gt; object returned by the
request’s &lt;tt&gt;getReader&lt;/tt&gt; method. To read binary data, use the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletInputStream.html"&gt;ServletInputStream&lt;/a&gt; returned by
&lt;tt&gt;getInputStream&lt;/tt&gt;.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-244"&gt;&lt;/a&gt;&lt;a name="indexterm-245"&gt;&lt;/a&gt;&lt;a name="indexterm-246"&gt;&lt;/a&gt;HTTP servlets are passed an HTTP request object, &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html"&gt;HttpServletRequest&lt;/a&gt;, which contains the request
URL, HTTP headers, query string, and so on.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-247"&gt;&lt;/a&gt;An HTTP request URL contains the following parts:&lt;/p&gt;&lt;pre&gt;http://[&lt;i&gt;host&lt;/i&gt;]:[&lt;i&gt;port&lt;/i&gt;][&lt;i&gt;request-path&lt;/i&gt;]?[&lt;i&gt;query-string&lt;/i&gt;]&lt;/pre&gt;&lt;p&gt;&lt;a name="indexterm-248"&gt;&lt;/a&gt;The request path is further composed of the following elements:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Context path&lt;/b&gt;: A concatenation of a forward slash (&lt;tt&gt;/&lt;/tt&gt;) with the context root of the servlet’s web application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;b&gt;Servlet path&lt;/b&gt;: The path section that corresponds to the component alias that activated this request. This path starts with a forward slash (&lt;tt&gt;/&lt;/tt&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;b&gt;Path info&lt;/b&gt;: The part of the request path that is not part of the context path or the servlet path.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;If the context path is &lt;tt&gt;/catalog&lt;/tt&gt; and for the aliases listed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafv.html#bnafx"&gt;Table 4-4&lt;/a&gt;,
&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafv.html#bnafy"&gt;Table 4-5&lt;/a&gt; gives some examples of how the URL will be parsed.&lt;/p&gt;&lt;a name="bnafx"&gt;&lt;/a&gt;&lt;h6&gt;Table 4-4 Aliases&lt;/h6&gt;&lt;table ID="Table1"&gt;&lt;col width="178*"&gt;&lt;col width="178*"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th align="left" valign="top"&gt;&lt;p&gt;Pattern&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;Servlet&lt;/p&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;/lawn/*&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;LawnServlet&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;/*.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;JSPServlet&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;a name="bnafy"&gt;&lt;/a&gt;&lt;h6&gt;Table 4-5 Request Path Elements&lt;/h6&gt;&lt;table ID="Table2"&gt;&lt;col width="162*"&gt;&lt;col width="116*"&gt;&lt;col width="77*"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th align="left" valign="top"&gt;&lt;p&gt;Request Path&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;Servlet Path&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;Path
Info&lt;/p&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;/catalog/lawn/index.html&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;/lawn&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;/index.html&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;/catalog/help/feedback.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;/help/feedback.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;null&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;a name="indexterm-249"&gt;&lt;/a&gt;Query strings are composed of a set of parameters and values. Individual parameters
are retrieved from a request by using the &lt;tt&gt;getParameter&lt;/tt&gt; method. There are
two ways to generate query strings:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;A query string can explicitly appear in a web page. For example, an HTML page generated by &lt;tt&gt;CatalogServlet&lt;/tt&gt; could contain the link &lt;tt&gt;&amp;lt;a href="/bookstore1/catalog?Add=101"&amp;gt;Add To Cart&amp;lt;/a&amp;gt;&lt;/tt&gt;. &lt;tt&gt;CatalogServlet&lt;/tt&gt; extracts the parameter named &lt;tt&gt;Add&lt;/tt&gt; as follows:&lt;/p&gt;&lt;pre&gt;String bookId = request.getParameter("Add");&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A query string is appended to a URL when a form with a &lt;tt&gt;GET&lt;/tt&gt; HTTP method is submitted. In the Duke’s Bookstore application, &lt;tt&gt;CashierServlet&lt;/tt&gt; generates a form, then a user name input to the form is appended to the URL that maps to &lt;tt&gt;ReceiptServlet&lt;/tt&gt;, and finally &lt;tt&gt;ReceiptServlet&lt;/tt&gt; extracts the user name using the &lt;tt&gt;getParameter&lt;/tt&gt; method.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;


&lt;a name="bnafz"&gt;&lt;/a&gt;&lt;h4&gt;Constructing Responses&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-250"&gt;&lt;/a&gt;&lt;a name="indexterm-251"&gt;&lt;/a&gt;&lt;a name="indexterm-252"&gt;&lt;/a&gt;A response contains data passed between a server and the client. All responses
implement the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletResponse.html"&gt;ServletResponse&lt;/a&gt; interface. This interface defines methods that allow you to:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-253"&gt;&lt;/a&gt;&lt;a name="indexterm-254"&gt;&lt;/a&gt;&lt;a name="indexterm-255"&gt;&lt;/a&gt;&lt;a name="indexterm-256"&gt;&lt;/a&gt;Retrieve an output stream to use to send data to the client. To send character data, use the &lt;a href="http://java.sun.com/javase/6/docs/api/java/io/PrintWriter.html"&gt;PrintWriter&lt;/a&gt; returned by the response’s &lt;tt&gt;getWriter&lt;/tt&gt; method. To send binary data in a MIME body response, use the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletOutputStream.html"&gt;ServletOutputStream&lt;/a&gt; returned by &lt;tt&gt;getOutputStream&lt;/tt&gt;. To mix binary and text data (as in a multipart response), use a &lt;tt&gt;ServletOutputStream&lt;/tt&gt; and manage the character sections manually.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Indicate the content type (for example, &lt;tt&gt;text/html&lt;/tt&gt;) being returned by the response with the &lt;tt&gt;setContentType(String)&lt;/tt&gt;
method. This method must be called before the response is committed. A
registry of content type names is kept by the Internet Assigned Numbers
Authority (IANA) at &lt;a href="http://www.iana.org/assignments/media-types/"&gt;http://www.iana.org/assignments/media-types/&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-257"&gt;&lt;/a&gt;Indicate whether to buffer output with the &lt;tt&gt;setBufferSize(int)&lt;/tt&gt;
method. By default, any content written to the output stream is
immediately sent to the client. Buffering allows content to be written
before anything is actually sent back to the client, thus providing the
servlet with more time to set appropriate status codes and headers or
forward to another web resource. The method must be called before any
content is written or before the response is committed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set localization information such as locale and character encoding. See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaxu.html"&gt;Chapter 15, Internationalizing and Localizing Web Applications&lt;/a&gt; for details.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;a name="indexterm-258"&gt;&lt;/a&gt;&lt;a name="indexterm-259"&gt;&lt;/a&gt;&lt;a name="indexterm-260"&gt;&lt;/a&gt;HTTP response objects, &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletResponse.html"&gt;HttpServletResponse&lt;/a&gt;, have fields representing HTTP headers such as the following:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Status codes, which are used to indicate the reason a request is not satisfied or that a request has been redirected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cookies, which are used to store application-specific
information at the client. Sometimes cookies are used to maintain an
identifier for tracking a user’s session (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagm.html#bnagr"&gt;Session Tracking&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;In Duke’s Bookstore, &lt;tt&gt;BookDetailsServlet&lt;/tt&gt; generates an HTML page that displays information about a
book that the servlet retrieves from a database. The servlet first sets response
headers: the content type of the response and the buffer size. The servlet
buffers the page content because the database access can generate an exception that
would cause forwarding to an error page. By buffering the response, the servlet
prevents the client from seeing a concatenation of part of a Duke’s Bookstore
page with the error page should an error occur. The &lt;tt&gt;doGet&lt;/tt&gt; method then retrieves
a &lt;tt&gt;PrintWriter&lt;/tt&gt; from the response.&lt;/p&gt;&lt;p&gt;To fill in the response, the servlet first dispatches the request to
&lt;tt&gt;BannerServlet&lt;/tt&gt;, which generates a common banner for all the servlets in the application.
This process is discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagi.html#bnagj"&gt;Including Other Resources in the Response&lt;/a&gt;. Then the servlet retrieves the book identifier
from a request parameter and uses the identifier to retrieve information about the
book from the bookstore database. Finally, the servlet generates HTML markup that describes
the book information and then commits the response to the client by calling
the &lt;tt&gt;close&lt;/tt&gt; method on the &lt;tt&gt;PrintWriter&lt;/tt&gt;.&lt;/p&gt;&lt;pre&gt;public class BookDetailsServlet extends HttpServlet {
     ...
     public void doGet (HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
        ...
        // set headers before accessing the Writer
        response.setContentType("text/html");
        response.setBufferSize(8192);
        PrintWriter out = response.getWriter();

        // then write the response
        out.println("&amp;lt;html&amp;gt;" +
            "&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;+
            messages.getString("TitleBookDescription")
            +&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;");

        // Get the dispatcher; it gets the banner to the user
        RequestDispatcher dispatcher =
            getServletContext().
            getRequestDispatcher("/banner");
        if (dispatcher != null)
            dispatcher.include(request, response);

        // Get the identifier of the book to display
        String bookId = request.getParameter("bookId");
        if (bookId != null) {
            // and the information about the book
            try {
                Book bd =
                    bookDB.getBook(bookId);
                ...
                // Print the information obtained
                out.println("&amp;lt;h2&amp;gt;" + bd.getTitle() + "&amp;lt;/h2&amp;gt;" +
                ...
            } catch (BookNotFoundException ex) {
                response.resetBuffer();
                throw new ServletException(ex);
            }
        }
        out.println("&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;");
        out.close();
    }
}&lt;/pre&gt;&lt;p&gt;&lt;tt&gt;BookDetailsServlet&lt;/tt&gt; generates a page that looks like &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafv.html#bnaga"&gt;Figure 4-2&lt;/a&gt;.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=14212247090&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Filtering Requests and Responses</title><link>http://www.softxml.com/LearnTutorial.asp?id=33161818589&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;A &lt;b&gt;filter&lt;/b&gt; is an object that can transform the header and content (or
both) of a request or response. Filters differ from web components in that
filters usually do not themselves create a response. Instead, a filter provides functionality that
can be “attached” to any kind of web resource. Consequently, a filter should
not have any dependencies on a web resource for which it is acting
as a filter; this way it can be composed with more than
one type of web resource. &lt;/p&gt;&lt;p&gt;The main tasks that a filter can perform are as follows:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Query the request and act accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Block the request-and-response pair from passing any further.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modify the request headers and data. You do this by providing a customized version of the request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modify the response headers and data. You do this by providing a customized version of the response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interact with external resources.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Applications of filters include authentication, logging, image conversion, data compression, encryption, tokenizing streams,
XML transformations, and so on.&lt;/p&gt;&lt;p&gt;You can configure a web resource to be filtered by a chain
of zero, one, or more filters in a specific order. This chain is
specified when the web application containing the component is deployed and is instantiated
when a web container loads the component.&lt;/p&gt;&lt;p&gt;In summary, the tasks involved in using filters are&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Programming the filter&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Programming customized requests and responses&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Specifying the filter chain for each web resource&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;


&lt;a name="bnagc"&gt;&lt;/a&gt;&lt;h4&gt;Programming Filters&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-262"&gt;&lt;/a&gt;&lt;a name="indexterm-263"&gt;&lt;/a&gt;&lt;a name="indexterm-264"&gt;&lt;/a&gt;&lt;a name="indexterm-265"&gt;&lt;/a&gt;The filtering API is defined by the &lt;tt&gt;Filter&lt;/tt&gt;, &lt;tt&gt;FilterChain&lt;/tt&gt;, and &lt;tt&gt;FilterConfig&lt;/tt&gt; interfaces in the
&lt;tt&gt;javax.servlet&lt;/tt&gt; package. You define a filter by implementing the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/Filter.html"&gt;Filter&lt;/a&gt; interface. &lt;/p&gt;&lt;p&gt;The most important method in this interface is &lt;tt&gt;doFilter&lt;/tt&gt;, which is passed request,
response, and filter chain objects. This method can perform the following actions:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Examine the request headers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Customize the request object if the filter wishes to modify request headers or data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Customize the response object if the filter wishes to modify response headers or data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Invoke the next entity in the filter chain. If the current
filter is the last filter in the chain that ends with the target web
component or static resource, the next entity is the resource at the
end of the chain; otherwise, it is the next filter that was configured
in the WAR. The filter invokes the next entity by calling the &lt;tt&gt;doFilter&lt;/tt&gt;
method on the chain object (passing in the request and response it was
called with, or the wrapped versions it may have created).
Alternatively, it can choose to block the request by not making the
call to invoke the next entity. In the latter case, the filter is
responsible for filling out the response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Examine response headers after it has invoked the next filter in the chain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Throw an exception to indicate an error in processing.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;a name="indexterm-266"&gt;&lt;/a&gt;In addition to &lt;tt&gt;doFilter&lt;/tt&gt;, you must implement the &lt;tt&gt;init&lt;/tt&gt; and &lt;tt&gt;destroy&lt;/tt&gt; methods. The
&lt;tt&gt;init&lt;/tt&gt; method is called by the container when the filter is instantiated. If
you wish to pass initialization parameters to the filter, you retrieve them from
the &lt;tt&gt;FilterConfig&lt;/tt&gt; object passed to &lt;tt&gt;init&lt;/tt&gt;.&lt;/p&gt;&lt;p&gt;The Duke’s Bookstore application uses the filters &lt;tt&gt;HitCounterFilter&lt;/tt&gt; and &lt;tt&gt;OrderFilter&lt;/tt&gt;, located at
&lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore1/src/java/com/sun/bookstore1/filters/&lt;/tt&gt;, to increment and log the value of counters when the entry
and receipt servlets are accessed.&lt;/p&gt;&lt;p&gt;In the &lt;tt&gt;doFilter&lt;/tt&gt; method, both filters retrieve the servlet context from the filter
configuration object so that they can access the counters stored as context attributes.
After the filters have completed application-specific processing, they invoke &lt;tt&gt;doFilter&lt;/tt&gt; on the filter chain
object passed into the original &lt;tt&gt;doFilter&lt;/tt&gt; method. The elided code is discussed in
the next section.&lt;/p&gt;&lt;pre&gt;public final class HitCounterFilter implements Filter {
    private FilterConfig filterConfig = null;

    public void init(FilterConfig filterConfig)
         throws ServletException {
        this.filterConfig = filterConfig;
    }
    public void destroy() {
        this.filterConfig = null;
    }
    public void doFilter(ServletRequest request,
        ServletResponse response, FilterChain chain)
         throws IOException, ServletException {
        if (filterConfig == null)
            return;
        StringWriter sw = new StringWriter();
        PrintWriter writer = new PrintWriter(sw);
        Counter counter = (Counter)filterConfig.
            getServletContext().
            getAttribute("hitCounter");
        writer.println();
        writer.println("===============");
        writer.println("The number of hits is: " +
            counter.incCounter());
        writer.println("===============");
        // Log the resulting string
        writer.flush();
        System.out.println(sw.getBuffer().toString());
        ...
        chain.doFilter(request, wrapper);
        ...
    }
}&lt;/pre&gt;

&lt;a name="bnagd"&gt;&lt;/a&gt;&lt;h4&gt;Programming Customized Requests and Responses&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-267"&gt;&lt;/a&gt;&lt;a name="indexterm-268"&gt;&lt;/a&gt;There are many ways for a filter to modify a request or
response. For example, a filter can add an attribute to the request or
can insert data in the response. In the Duke’s Bookstore example, &lt;tt&gt;HitCounterFilter&lt;/tt&gt; inserts
the value of the counter into the response.&lt;/p&gt;&lt;p&gt;A filter that modifies a response must usually capture the response before it
is returned to the client. To do this, you pass a stand-in
stream to the servlet that generates the response. The stand-in stream prevents the servlet
from closing the original response stream when it completes and allows the filter
to modify the servlet’s response.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-269"&gt;&lt;/a&gt;To pass this stand-in stream to the servlet, the filter creates a response
wrapper that overrides the &lt;tt&gt;getWriter&lt;/tt&gt; or &lt;tt&gt;getOutputStream&lt;/tt&gt; method to return this stand-in
stream. The wrapper is passed to the &lt;tt&gt;doFilter&lt;/tt&gt; method of the filter chain.
Wrapper methods default to calling through to the wrapped request or response object.
This approach follows the well-known Wrapper or Decorator pattern described in &lt;b&gt;Design Patterns, Elements of Reusable Object-Oriented Software&lt;/b&gt;, by Erich
Gamma et al. (Addison-Wesley, 1995). The following sections describe how the hit counter
filter described earlier and other types of filters use wrappers.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-270"&gt;&lt;/a&gt;&lt;a name="indexterm-271"&gt;&lt;/a&gt;To override request methods, you wrap the request in an object that extends
&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequestWrapper.html"&gt;ServletRequestWrapper&lt;/a&gt; or &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequestWrapper.html"&gt;HttpServletRequestWrapper&lt;/a&gt;. To override response methods, you wrap the response in an
object that extends &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletResponseWrapper.html"&gt;ServletResponseWrapper&lt;/a&gt; or &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletResponseWrapper.html"&gt;HttpServletResponseWrapper&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;tt&gt;HitCounterFilter&lt;/tt&gt; wraps the response in a &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore1/src/java/com/sun/bookstore1/filters/CharResponseWrapper&lt;/tt&gt;. The wrapped response is passed
to the next object in the filter chain, which is &lt;tt&gt;BookStoreServlet&lt;/tt&gt;. Then &lt;tt&gt;BookStoreServlet&lt;/tt&gt;
writes its response into the stream created by &lt;tt&gt;CharResponseWrapper&lt;/tt&gt;. When &lt;tt&gt;chain.doFilter&lt;/tt&gt; returns,
&lt;tt&gt;HitCounterFilter&lt;/tt&gt; retrieves the servlet’s response from &lt;tt&gt;PrintWriter&lt;/tt&gt; and writes it to a buffer.
The filter inserts the value of the counter into the buffer, resets the
content length header of the response, and then writes the contents of the
buffer to the response stream.&lt;/p&gt;&lt;pre&gt;PrintWriter out = response.getWriter();
CharResponseWrapper wrapper = new CharResponseWrapper(
    (HttpServletResponse)response);
chain.doFilter(request, wrapper);
CharArrayWriter caw = new CharArrayWriter();
caw.write(wrapper.toString().substring(0,
    wrapper.toString().indexOf("&amp;lt;/body&amp;gt;")-1));
caw.write("&amp;lt;p&amp;gt;\n&amp;lt;center&amp;gt;" +
     messages.getString("Visitor") + "&amp;lt;font color=’red’&amp;gt;" +
     counter.getCounter() + "&amp;lt;/font&amp;gt;&amp;lt;/center&amp;gt;");
caw.write("\n&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;");
response.setContentLength(caw.toString().getBytes().length);
out.write(caw.toString());
out.close();

public class CharResponseWrapper extends
    HttpServletResponseWrapper {
    private CharArrayWriter output;
    public String toString() {
        return output.toString();
    }
    public CharResponseWrapper(HttpServletResponse response){
        super(response);
        output = new CharArrayWriter();
    }
    public PrintWriter getWriter(){
        return new PrintWriter(output);
    }
}&lt;/pre&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagb.html#bnage"&gt;Figure 4-3&lt;/a&gt; shows the entry page for Duke’s Bookstore with the hit counter.&lt;/p&gt;&lt;a name="bnage"&gt;&lt;/a&gt;&lt;h6&gt;Figure 4-3 Duke’s Bookstore with Hit Counter&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/web-dukesBookstore.gif" alt="Screen capture of Duke&amp;#8216;s Bookstore with " components="" for="" web="" developers="" recommendation,="" start="" shopping="" link="" and="" you="" are="" visitor="" number="" 2.="" height="627" width="662"&gt;

&lt;a name="bnagf"&gt;&lt;/a&gt;&lt;h4&gt;Specifying Filter Mappings&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-272"&gt;&lt;/a&gt;&lt;a name="indexterm-273"&gt;&lt;/a&gt;&lt;a name="indexterm-274"&gt;&lt;/a&gt;&lt;a name="indexterm-275"&gt;&lt;/a&gt;A web container uses filter mappings to decide how to apply filters to
web resources. A filter mapping matches a filter to a web component by
name, or to web resources by URL pattern. The filters are invoked in
the order in which filter mappings appear in the filter mapping list of
a WAR. You specify a filter mapping list for a WAR in its
deployment descriptor, either with NetBeans IDE or by coding the list by hand
with XML.&lt;/p&gt;&lt;p&gt;To declare the filter and map it to a web resource using
NetBeans IDE, do the following:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Expand the application’s project node in the Project pane.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expand the Web Pages and WEB-INF nodes under the project node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Double-click &lt;tt&gt;web.xml&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Filters at the top of the editor pane.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expand the Servlet Filters node in the editor pane.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Add Filter Element to map the filter to a web resource by name or by URL pattern.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Add Servlet Filter dialog, enter the name of the filter in the Filter Name field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Browse to locate the servlet class to which the filter
applies. You can include wildcard characters so that you can apply the
filter to more than one servlet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click OK.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;To constrain how the filter is applied to requests, do the following:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Expand the Filter Mappings node in the Filters tab of the editor pane.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the filter from the list of filters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Add.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Add Filter Mapping dialog, select one of the following dispatcher types:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;tt&gt;REQUEST&lt;/tt&gt;: Only when the request comes directly from the client&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;FORWARD&lt;/tt&gt;: Only when the request has been forwarded to a component (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagi.html#bnagk"&gt;Transferring Control to Another Web Component&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;INCLUDE&lt;/tt&gt;: Only when the request is being processed by a component that has been included (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagi.html#bnagj"&gt;Including Other Resources in the Response&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;ERROR&lt;/tt&gt;: Only when the request is being processed with the error page mechanism (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafi.html#bnafn"&gt;Handling Servlet Errors&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;You
can direct the filter to be applied to any combination of the preceding
situations by selecting multiple dispatcher types. If no types are
specified, the default option is &lt;tt&gt;REQUEST&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;You can declare, map, and constrain the filter by editing the XML
in the web application deployment descriptor directly by following these steps:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;While in the &lt;tt&gt;web.xml&lt;/tt&gt; editor pane in NetBeans IDE, click XML at the top of the editor pane.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare the filter by adding a &lt;tt&gt;filter&lt;/tt&gt; element right after the &lt;tt&gt;display-name&lt;/tt&gt; element. The &lt;tt&gt;filter&lt;/tt&gt; element creates a name for the filter and declares the filter’s implementation class and initialization parameters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Map the filter to a web resource by name or by URL pattern using the &lt;tt&gt;filter-mapping&lt;/tt&gt; element:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Include a &lt;tt&gt;filter-name&lt;/tt&gt; element that specifies the name of the filter as defined by the &lt;tt&gt;filter&lt;/tt&gt; element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Include a &lt;tt&gt;servlet-name&lt;/tt&gt; element that specifies to which servlet the filter applies. The &lt;tt&gt;servlet-name&lt;/tt&gt; element can include wildcard characters so that you can apply the filter to more than one servlet.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Constrain how the filter will be applied to requests by
specifying one of the enumerated dispatcher options (described in step
4 of the preceding set of steps) with the &lt;tt&gt;dispatcher&lt;/tt&gt; element and adding the &lt;tt&gt;dispatcher&lt;/tt&gt; element to the &lt;tt&gt;filter-mapping&lt;/tt&gt; element.&lt;/p&gt;&lt;p&gt;You can direct the filter to be applied to any combination of the preceding situations by including multiple &lt;tt&gt;dispatcher&lt;/tt&gt; elements. If no elements are specified, the default option is &lt;tt&gt;REQUEST&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;If you want to log every request to a web application, you
map the hit counter filter to the URL pattern &lt;tt&gt;/*&lt;/tt&gt;. &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagb.html#bnagg"&gt;Table 4-6&lt;/a&gt; summarizes the
filter definition and mapping list for the Duke’s Bookstore application. The filters are
matched by servlet name, and each filter chain contains only one filter.&lt;/p&gt;&lt;a name="bnagg"&gt;&lt;/a&gt;&lt;h6&gt;Table 4-6 Duke’s Bookstore Filter Definition and Mapping List&lt;/h6&gt;&lt;table ID="Table1"&gt;&lt;col width="90*"&gt;&lt;col width="144*"&gt;&lt;col width="106*"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th align="left" valign="top"&gt;&lt;p&gt;Filter&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;Class&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;Servlet&lt;/p&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;HitCounterFilter&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;filters.HitCounterFilter&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;BookStoreServlet&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;OrderFilter&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;filters.OrderFilter&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;ReceiptServlet&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;a name="indexterm-276"&gt;&lt;/a&gt;&lt;a name="indexterm-277"&gt;&lt;/a&gt;You can map a filter to one or more web resources and you
can map more than one filter to a web resource. This is illustrated
in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagb.html#bnagh"&gt;Figure 4-4&lt;/a&gt;, where filter F1 is mapped to servlets S1, S2, and S3,
filter F2 is mapped to servlet S2, and filter F3 is mapped to
servlets S1 and S2.&lt;/p&gt;&lt;a name="bnagh"&gt;&lt;/a&gt;&lt;h6&gt;Figure 4-4 Filter-to-Servlet Mapping&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/web-filterMapping.gif" alt="Diagram of filter-to-servlet mapping with filters F1-F3 and servlets S1-S3. F1 filters S1-S3, then F2 filters S2, then F3 filters S1 and S2."&gt;&lt;p&gt;&lt;a name="indexterm-278"&gt;&lt;/a&gt;&lt;a name="indexterm-279"&gt;&lt;/a&gt;Recall that a filter chain is one of the objects passed to the
&lt;tt&gt;doFilter&lt;/tt&gt; method of a filter. This chain is formed indirectly by means of
filter mappings. The order of the filters in the chain is the same
as the order in which filter mappings appear in the web application deployment
descriptor.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-280"&gt;&lt;/a&gt;&lt;a name="indexterm-281"&gt;&lt;/a&gt;When a filter is mapped to servlet S1, the web container invokes the
&lt;tt&gt;doFilter&lt;/tt&gt; method of F1.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=33161818589&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Invoking Other Web Resources</title><link>http://www.softxml.com/LearnTutorial.asp?id=45700547695&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;Web components can invoke other web resources in two ways: indirectly and directly.
A web component indirectly invokes another web resource when it embeds a URL
that points to another web component in content returned to a client. In
the Duke’s Bookstore application, most web components contain embedded URLs that point to
other web components. For example, &lt;tt&gt;ShowCartServlet&lt;/tt&gt; indirectly invokes the &lt;tt&gt;CatalogServlet&lt;/tt&gt; through the following
embedded URL:&lt;/p&gt;&lt;pre&gt;/bookstore1/catalog&lt;/pre&gt;&lt;p&gt;A web component can also directly invoke another resource while it is executing.
There are two possibilities: The web component can include the content of another
resource, or it can forward a request to another resource.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-283"&gt;&lt;/a&gt;&lt;a name="indexterm-284"&gt;&lt;/a&gt;To invoke a resource available on the server that is running a web
component, you must first obtain a &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/RequestDispatcher.html"&gt;RequestDispatcher&lt;/a&gt; object using the &lt;tt&gt;getRequestDispatcher("URL")&lt;/tt&gt; method.&lt;/p&gt;&lt;p&gt;You can get a &lt;tt&gt;RequestDispatcher&lt;/tt&gt; object from either a request or the web
context; however, the two methods have slightly different behavior. The method takes the
path to the requested resource as an argument. A request can take a
relative path (that is, one that does not begin with a &lt;tt&gt;/&lt;/tt&gt;), but
the web context requires an absolute path. If the resource is not available
or if the server has not implemented a &lt;tt&gt;RequestDispatcher&lt;/tt&gt; object for that
type of resource, &lt;tt&gt;getRequestDispatcher&lt;/tt&gt; will return null. Your servlet should be prepared to
deal with this condition.&lt;/p&gt;

&lt;a name="bnagj"&gt;&lt;/a&gt;&lt;h4&gt;Including Other Resources in the Response&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-285"&gt;&lt;/a&gt;&lt;a name="indexterm-286"&gt;&lt;/a&gt;It is often useful to include another web resource (for example, banner content
or copyright information) in the response returned from a web component. To include
another resource, invoke the &lt;tt&gt;include&lt;/tt&gt; method of a &lt;tt&gt;RequestDispatcher&lt;/tt&gt; object:&lt;/p&gt;&lt;pre&gt;include(request, response);&lt;/pre&gt;&lt;p&gt;If the resource is static, the &lt;tt&gt;include&lt;/tt&gt; method enables programmatic server-side includes. If
the resource is a web component, the effect of the method is to
send the request to the included web component, execute the web component, and
then include the result of the execution in the response from the containing
servlet. An included web component has access to the request object, but it
is limited in what it can do with the response object:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;It can write to the body of the response and commit a response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It cannot set headers or call any method (for example, &lt;tt&gt;setCookie&lt;/tt&gt;) that affects the headers of the response.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The banner for the Duke’s Bookstore application is generated by &lt;tt&gt;BannerServlet&lt;/tt&gt;. Note
that both &lt;tt&gt;doGet&lt;/tt&gt; and &lt;tt&gt;doPost&lt;/tt&gt; are implemented because &lt;tt&gt;BannerServlet&lt;/tt&gt; can be dispatched from
either method in a calling servlet.&lt;/p&gt;&lt;pre&gt;public class BannerServlet extends HttpServlet {
     public void doGet (HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {
            output(request, response);
    }
    public void doPost (HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {
            output(request, response);
}

private void output(HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println("&amp;lt;body bgcolor=\"#ffffff\"&amp;gt;" +
        "&amp;lt;center&amp;gt;" + "&amp;lt;hr&amp;gt; &amp;lt;br&amp;gt; &amp;amp;nbsp;" + "&amp;lt;h1&amp;gt;" +
        "&amp;lt;font size=\"+3\" color=\"#CC0066\"&amp;gt;Duke’s &amp;lt;/font&amp;gt;" +
        &amp;lt;img src=\"" + request.getContextPath() +
        "/duke.books.gif\"&amp;gt;" +
         "&amp;lt;font size=\"+3\" color=\"black\"&amp;gt;Bookstore&amp;lt;/font&amp;gt;" +
        "&amp;lt;/h1&amp;gt;" + "&amp;lt;/center&amp;gt;" + "&amp;lt;br&amp;gt; &amp;amp;nbsp; &amp;lt;hr&amp;gt; &amp;lt;br&amp;gt; ");
    }
}&lt;/pre&gt;&lt;p&gt;Each servlet in the Duke’s Bookstore application includes the result from &lt;tt&gt;BannerServlet&lt;/tt&gt; using
the following code:&lt;/p&gt;&lt;pre&gt;RequestDispatcher dispatcher =
    getServletContext().getRequestDispatcher("/banner");
if (dispatcher != null)
    dispatcher.include(request, response);
}&lt;/pre&gt;

&lt;a name="bnagk"&gt;&lt;/a&gt;&lt;h4&gt;Transferring Control to Another Web Component&lt;/h4&gt;
&lt;p&gt;In some applications, you might want to have one web component do
preliminary processing of a request and have another component generate the response. For example,
you might want to partially process a request and then transfer to another
component depending on the nature of the request.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-287"&gt;&lt;/a&gt;&lt;a name="indexterm-288"&gt;&lt;/a&gt;To transfer control to another web component, you invoke the &lt;tt&gt;forward&lt;/tt&gt; method of
a &lt;tt&gt;RequestDispatcher&lt;/tt&gt;. When a request is forwarded, the request URL is set to
the path of the forwarded page. The original URI and its constituent parts
are saved as request attributes &lt;tt&gt;javax.servlet.forward.[&lt;i&gt;request-uri&lt;/i&gt;|&lt;i&gt;context-path&lt;/i&gt;|&lt;i&gt;servlet-path&lt;/i&gt;|&lt;i&gt;path-info&lt;/i&gt;|&lt;i&gt;query-string&lt;/i&gt;]&lt;/tt&gt;. The &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore2/src/java/com/sun/bookstore2/dispatcher/Dispatcher&lt;/tt&gt; servlet, used by a
version of the Duke’s Bookstore application described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnall.html"&gt;The Example JSP Pages&lt;/a&gt;, saves the path information from
the original URL, retrieves a &lt;tt&gt;RequestDispatcher&lt;/tt&gt; from the request, and then forwards
to the JSP page, &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore3/web/template/template.jsp&lt;/tt&gt;.&lt;/p&gt;&lt;pre&gt;public class Dispatcher extends HttpServlet {
    public void doGet(HttpServletRequest request,
         HttpServletResponse response) {
        RequestDispatcher dispatcher = request.
            getRequestDispatcher("/template.jsp");
        if (dispatcher != null)
            dispatcher.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=45700547695&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Accessing the Web Context</title><link>http://www.softxml.com/LearnTutorial.asp?id=38930331778&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;The context in which web components execute is an object that implements the
&lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html"&gt;ServletContext&lt;/a&gt; interface. You retrieve the web context using the &lt;tt&gt;getServletContext&lt;/tt&gt; method. The web
context provides methods for accessing:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Initialization parameters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resources associated with the web context&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Object-valued attributes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logging capabilities&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The web context is used by the Duke’s Bookstore filters &lt;tt&gt;HitCounterFilter&lt;/tt&gt; and
&lt;tt&gt;OrderFilter&lt;/tt&gt;, which are discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagb.html"&gt;Filtering Requests and Responses&lt;/a&gt;. Each filter stores a counter as a
context attribute. Recall from &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafo.html#bnafs"&gt;Controlling Concurrent Access to Shared Resources&lt;/a&gt; that the counter’s access methods are synchronized to
prevent incompatible operations by servlets that are running concurrently. A filter retrieves the
counter object using the context’s &lt;tt&gt;getAttribute&lt;/tt&gt; method. The incremented value of the counter is
recorded in the log.&lt;/p&gt;&lt;pre&gt;public final class HitCounterFilter implements Filter {
    private FilterConfig filterConfig = null;
    public void doFilter(ServletRequest request,
        ServletResponse response, FilterChain chain)
         throws IOException, ServletException {
        ...</description><guid>http://www.softxml.com/LearnTutorial.asp?id=38930331778&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Maintaining Client State</title><link>http://www.softxml.com/LearnTutorial.asp?id=25714283850&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;Many applications require that a series of requests from a client be associated
with one another. For example, the Duke’s Bookstore application saves the state of
a user’s shopping cart across requests. Web-based applications are responsible for maintaining such
state, called a &lt;b&gt;session&lt;/b&gt;, because HTTP is stateless. To support applications that
need to maintain state, Java Servlet technology provides an API for managing sessions and
allows several mechanisms for implementing sessions.&lt;/p&gt;

&lt;a name="bnagn"&gt;&lt;/a&gt;&lt;h4&gt;Accessing a Session&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-294"&gt;&lt;/a&gt;&lt;a name="indexterm-295"&gt;&lt;/a&gt;Sessions are represented by an &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSession.html"&gt;HttpSession&lt;/a&gt; object. You access a session by
calling the &lt;tt&gt;getSession&lt;/tt&gt; method of a request object. This method returns the
current session associated with this request, or, if the request does not have
a session, it creates one.&lt;/p&gt;

&lt;a name="bnago"&gt;&lt;/a&gt;&lt;h4&gt;Associating Objects with a Session&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-296"&gt;&lt;/a&gt;You can associate object-valued attributes with a session by name. Such attributes are
accessible by any web component that belongs to the same web context &lt;b&gt;and&lt;/b&gt;
is handling a request that is part of the same session.&lt;/p&gt;&lt;p&gt;The Duke’s Bookstore application stores a customer’s shopping cart as a session attribute.
This allows the shopping cart to be saved between requests and also allows
cooperating servlets to access the cart. &lt;tt&gt;CatalogServlet&lt;/tt&gt; adds items to the cart;
&lt;tt&gt;ShowCartServlet&lt;/tt&gt; displays, deletes items from, and clears the cart; and &lt;tt&gt;CashierServlet&lt;/tt&gt; retrieves the total
cost of the books in the cart.&lt;/p&gt;&lt;pre&gt;public class CashierServlet extends HttpServlet {
     public void doGet (HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {

        // Get the user’s session and shopping cart
        HttpSession session = request.getSession();
        ShoppingCart cart =
            (ShoppingCart)session.
                getAttribute("cart");
         ...
        // Determine the total price of the user’s books
        double total = cart.getTotal();&lt;/pre&gt;

&lt;a name="bnagp"&gt;&lt;/a&gt;&lt;h5&gt;Notifying Objects That Are Associated with a Session&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-297"&gt;&lt;/a&gt;Recall that your application can notify web context and session listener objects of
servlet life-cycle events (&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafi.html#bnafj"&gt;Handling Servlet Life-Cycle Events&lt;/a&gt;). You can also notify objects of certain events related
to their association with a session such as the following:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;When the object is added to or removed from a session. To receive this notification, your object must implement the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSessionBindingListener.html"&gt;javax.servlet.http.HttpSessionBindingListener&lt;/a&gt; interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When the session to which the object is attached will be
passivated or activated. A session will be passivated or activated when
it is moved between virtual machines or saved to and restored from
persistent storage. To receive this notification, your object must
implement the &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSessionActivationListener.html"&gt;javax.servlet.http.HttpSessionActivationListener&lt;/a&gt; interface.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;


&lt;a name="bnagq"&gt;&lt;/a&gt;&lt;h4&gt;Session Management&lt;/h4&gt;
&lt;p&gt;Because there is no way for an HTTP client to signal that
it no longer needs a session, each session has an associated timeout so
that its resources can be reclaimed. The timeout period can be accessed by
using a session’s &lt;tt&gt;[get|set]MaxInactiveInterval&lt;/tt&gt; methods. &lt;/p&gt;&lt;p&gt;You can also set the timeout period in the deployment descriptor using
NetBeans IDE:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Open the &lt;tt&gt;web.xml&lt;/tt&gt; file in the &lt;tt&gt;web.xml&lt;/tt&gt; editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click General at the top of the editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter an integer value in the Session Timeout field. The integer
value represents the number of minutes of inactivity that must pass
before the session times out.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;To ensure that an active session is not timed out, you should
periodically access the session by using service methods because this resets the session’s time-to-live
counter.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-298"&gt;&lt;/a&gt;&lt;a name="indexterm-299"&gt;&lt;/a&gt;When a particular client interaction is finished, you use the session’s &lt;tt&gt;invalidate&lt;/tt&gt; method
to invalidate a session on the server side and remove any session data.
The bookstore application’s &lt;tt&gt;ReceiptServlet&lt;/tt&gt; is the last servlet to access a client’s
session, so it has the responsibility to invalidate the session:&lt;/p&gt;&lt;pre&gt;public class ReceiptServlet extends HttpServlet {
     public void doPost(HttpServletRequest request,
                    HttpServletResponse response)
                     throws ServletException, IOException {
        // Get the user’s session and shopping cart
        HttpSession session = request.getSession();
        // Payment received -- invalidate the session
        session.invalidate();
        ...&lt;/pre&gt;

&lt;a name="bnagr"&gt;&lt;/a&gt;&lt;h4&gt;Session Tracking&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-300"&gt;&lt;/a&gt;A web container can use several methods to associate a session with a
user, all of which involve passing an identifier between the client and the
server. The identifier can be maintained on the client as a cookie, or
the web component can include the identifier in every URL that is
returned to the client.&lt;/p&gt;&lt;p&gt;If your application uses session objects, you must ensure that session tracking is
enabled by having the application rewrite URLs whenever the client turns off cookies.
You do this by calling the response’s &lt;tt&gt;encodeURL(URL)&lt;/tt&gt; method on all URLs
returned by a servlet. This method includes the session ID in the URL
only if cookies are disabled; otherwise, it returns the URL unchanged.&lt;/p&gt;&lt;p&gt;The &lt;tt&gt;doGet&lt;/tt&gt; method of &lt;tt&gt;ShowCartServlet&lt;/tt&gt; encodes the three URLs at the bottom of
the shopping cart display page as follows:&lt;/p&gt;&lt;pre&gt;out.println("&amp;lt;p&amp;gt; &amp;amp;nbsp; &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;a href=\"" +
    response.encodeURL(request.getContextPath() +
        "/bookcatalog") +
        "\"&amp;gt;" + messages.getString("ContinueShopping") +
        "&amp;lt;/a&amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;" +
        "&amp;lt;a href=\"" +
    response.encodeURL(request.getContextPath() +
        "/bookcashier") +
        "\"&amp;gt;" + messages.getString("Checkout") +
        "&amp;lt;/a&amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;" +
        "&amp;lt;a href=\"" +
     response.encodeURL(request.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=25714283850&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Finalizing a Servlet</title><link>http://www.softxml.com/LearnTutorial.asp?id=39578324488&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;When a servlet container determines that a servlet should be removed from 
	service (for example, when a container wants to reclaim memory resources or 
	when it is being shut down), the container calls the &lt;tt&gt;destroy&lt;/tt&gt; method of 
	the &lt;tt&gt;Servlet&lt;/tt&gt; interface. In this method, you release any resources the 
	servlet is using and save any persistent state. The following &lt;tt&gt;destroy&lt;/tt&gt; method 
	releases the database object created in the &lt;tt&gt;init&lt;/tt&gt; method described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafu.html"&gt;
		Initializing a Servlet&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;public void destroy() {
    bookDB = null;
}&lt;/pre&gt;
&lt;p&gt;All of a servlet’s service methods should be complete when a servlet is removed. 
	The server tries to ensure this by calling the &lt;tt&gt;destroy&lt;/tt&gt; method only 
	after all service requests have returned or after a server-specific grace 
	period, whichever comes first. If your servlet has operations that take a long 
	time to run (that is, operations that may run longer than the server’s grace 
	period), the operations could still be running when &lt;tt&gt;destroy&lt;/tt&gt; is called. 
	You must make sure that any threads still handling client requests complete; 
	the remainder of this section describes how to do the following:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		&lt;p&gt;Keep track of how many threads are currently running the &lt;tt&gt;service&lt;/tt&gt; method.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Provide a clean shutdown by having the &lt;tt&gt;destroy&lt;/tt&gt; method notify 
			long-running threads of the shutdown and wait for them to complete.&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;p&gt;Have the long-running methods poll periodically to check for shutdown and, if 
			necessary, stop working, clean up, and return.&lt;/p&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;a name="bnagt"&gt;&lt;/a&gt;
&lt;h4&gt;Tracking Service Requests&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-303"&gt;&lt;/a&gt;To track service requests, include in your servlet 
	class a field that counts the number of service methods that are running. The 
	field should have synchronized access methods to increment, decrement, and 
	return its value.&lt;/p&gt;
&lt;pre&gt;public class ShutdownExample extends HttpServlet {
    private int serviceCounter = 0;
    ...
    // Access methods for serviceCounter
    protected synchronized void enteringServiceMethod() {
        serviceCounter++;
    }
    protected synchronized void leavingServiceMethod() {
        serviceCounter--;
    }
    protected synchronized int numServices() {
        return serviceCounter;
    }
}&lt;/pre&gt;
&lt;p&gt;The &lt;tt&gt;service&lt;/tt&gt; method should increment the service counter each time the 
	method is entered and should decrement the counter each time the method 
	returns. This is one of the few times that your &lt;tt&gt;HttpServlet&lt;/tt&gt; subclass 
	should override the &lt;tt&gt;service&lt;/tt&gt; method. The new method should call &lt;tt&gt;super.service&lt;/tt&gt;
	to preserve the functionality of the original &lt;tt&gt;service&lt;/tt&gt; method:&lt;/p&gt;
&lt;pre&gt;protected void service(HttpServletRequest req,
                    HttpServletResponse resp)
                    throws ServletException,IOException {
    enteringServiceMethod();
    try {
        super.service(req, resp);
    } finally {
        leavingServiceMethod();
    }
}&lt;/pre&gt;
&lt;a name="bnagu"&gt;&lt;/a&gt;
&lt;h4&gt;Notifying Methods to Shut Down&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-304"&gt;&lt;/a&gt;To ensure a clean shutdown, your &lt;tt&gt;destroy&lt;/tt&gt; method 
	should not release any shared resources until all the service requests have 
	completed. One part of doing this is to check the service counter. Another part 
	is to notify the long-running methods that it is time to shut down. For this 
	notification, another field is required. The field should have the usual access 
	methods:&lt;/p&gt;
&lt;pre&gt;public class ShutdownExample extends HttpServlet {
    private boolean shuttingDown;
    ...
    //Access methods for shuttingDown
    protected synchronized void setShuttingDown(boolean flag) {
        shuttingDown = flag;
    }
    protected synchronized boolean isShuttingDown() {
        return shuttingDown;
    }
}&lt;/pre&gt;
&lt;p&gt;Here is an example of the &lt;tt&gt;destroy&lt;/tt&gt; method using these fields to provide 
	a clean shutdown:&lt;/p&gt;
&lt;pre&gt;public void destroy() {
    /* Check to see whether there are still service methods /*
    /* running, and if there are, tell them to stop. */
    if (numServices() &amp;gt; 0) {
        setShuttingDown(true);
    }

    /* Wait for the service methods to stop. */
    while(numServices() &amp;gt; 0) {
        try {
            Thread.sleep(interval);
        } catch (InterruptedException e) {
        }
    }
}&lt;/pre&gt;
&lt;a name="bnagv"&gt;&lt;/a&gt;
&lt;h4&gt;Creating Polite Long-Running Methods&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-305"&gt;&lt;/a&gt;The final step in providing a clean shutdown is to 
	make any long-running methods behave politely.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=39578324488&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>JavaServer Pages Technology</title><link>http://www.softxml.com/LearnTutorial.asp?id=48987283522&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;JavaServer Pages (JSP) technology allows you to easily create web content that has
both static and dynamic components. JSP technology makes available all the dynamic capabilities
of Java Servlet technology but provides a more natural approach to creating static
content.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=48987283522&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>What Is a JSP Page?</title><link>http://www.softxml.com/LearnTutorial.asp?id=44024696421&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;A &lt;b&gt;JSP page&lt;/b&gt; is a text document that contains two types of text: static
data, which can be expressed in any text-based format (such as &lt;a href="http://www.w3.org/MarkUp/"&gt;HTML&lt;/a&gt;, &lt;a href="http://www.w3.org/TR/SVG"&gt;SVG&lt;/a&gt;,
&lt;a href="http://xml.coverpages.org/wap-wml.html"&gt;WML&lt;/a&gt;, and &lt;a href="http://www.w3.org/TR/REC-xml/"&gt;XML&lt;/a&gt;), and JSP elements, which construct dynamic content.&lt;/p&gt;&lt;p&gt;The recommended file extension for the source file of a JSP page
is &lt;tt&gt;.jsp&lt;/tt&gt;. The page can be composed of a top file that
includes other files that contain either a complete JSP page or a fragment
of a JSP page. The recommended extension for the source file of a
fragment of a JSP page is &lt;tt&gt;.jspf&lt;/tt&gt;.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-309"&gt;&lt;/a&gt;&lt;a name="indexterm-310"&gt;&lt;/a&gt;The JSP elements in a JSP page can be expressed in two
syntaxes, standard and XML, though any given file can use only one syntax.
A JSP page in XML syntax is an XML document and can be
manipulated by tools and APIs for XML documents. This chapter and Chapters &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnakc.html"&gt;Chapter 7, JavaServer Pages Standard Tag Library&lt;/a&gt;
through &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaon.html"&gt;Chapter 9, Scripting in JSP Pages&lt;/a&gt; document only the standard syntax. The XML syntax is covered in
&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnajo.html"&gt;Chapter 6, JavaServer Pages Documents&lt;/a&gt;.&lt;/p&gt;

&lt;a name="bnagz"&gt;&lt;/a&gt;&lt;h4&gt;A Simple JSP Page Example&lt;/h4&gt;
&lt;p&gt;The web page in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnagy.html#bnaha"&gt;Figure 5-1&lt;/a&gt; is a form that allows you to select
a locale and displays the date in a manner appropriate to the locale.&lt;/p&gt;&lt;a name="bnaha"&gt;&lt;/a&gt;&lt;h6&gt;Figure 5-1 Localized Date Form&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/web-dateForm.gif" alt="Screen capture of localized date form. Locale drop-down shows Lithuanian. Get Date button displays the date, " antradienis,="" 2004,="" kovo="" 16.="" height="237" width="662"&gt;&lt;p&gt;&lt;a name="indexterm-311"&gt;&lt;/a&gt;The source code for this example is in the &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/date/&lt;/tt&gt; directory. The
JSP page, &lt;tt&gt;index.jsp&lt;/tt&gt;, appears below; it is a typical mixture of static HTML
markup and JSP elements. If you have developed web pages, you are probably
familiar with the HTML document structure statements (&lt;tt&gt;&amp;lt;head&amp;gt;&lt;/tt&gt;, &lt;tt&gt;&amp;lt;body&amp;gt;&lt;/tt&gt;, and so on) and the
HTML statements that create a form (&lt;tt&gt;&amp;lt;form&amp;gt;&lt;/tt&gt;) and a menu (&lt;tt&gt;&amp;lt;select&amp;gt;&lt;/tt&gt;).&lt;/p&gt;&lt;p&gt;The lines in bold in the example code contain the following types
of JSP constructs:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;A page directive (&lt;tt&gt;&lt;b&gt;&amp;lt;%@page ... %&amp;gt;&lt;/b&gt;&lt;/tt&gt;) sets the content type returned by the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tag library directives (&lt;tt&gt;&lt;b&gt;&amp;lt;%@taglib ... %&amp;gt;&lt;/b&gt;&lt;/tt&gt;) import custom tag libraries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;&lt;b&gt;jsp:useBean&lt;/b&gt;&lt;/tt&gt; is a standard element that creates
an object containing a collection of locales and initializes an
identifier that points to that object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JSP expression language expressions (&lt;tt&gt;&lt;b&gt;${ }&lt;/b&gt;&lt;/tt&gt;) retrieve the value of object properties. The values are used to set custom tag attribute values and create dynamic content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom tags (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnalj.html"&gt;Chapter 8, Custom Tags in JSP Pages&lt;/a&gt;) set a variable (&lt;tt&gt;&lt;b&gt;c:set&lt;/b&gt;&lt;/tt&gt;), iterate over a collection of locale names (&lt;tt&gt;&lt;b&gt;c:forEach&lt;/b&gt;&lt;/tt&gt;), and conditionally insert HTML text into the response (&lt;tt&gt;&lt;b&gt;c:if&lt;/b&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;b&gt;c:choose&lt;/b&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;b&gt;c:when&lt;/b&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;b&gt;c:otherwise&lt;/b&gt;&lt;/tt&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;&lt;b&gt;jsp:setProperty&lt;/b&gt;&lt;/tt&gt; is another standard element that sets the value of an object property.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A function (&lt;tt&gt;&lt;b&gt;f:equals&lt;/b&gt;&lt;/tt&gt;) tests the equality of an attribute and the current item of a collection. (A built-in &lt;tt&gt;==&lt;/tt&gt; operator is usually used to test equality.)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Here is the JSP page:&lt;/p&gt;&lt;pre&gt;&amp;lt;%@ &lt;b&gt;page contentType&lt;/b&gt;="text/html; charset=UTF-8" %&amp;gt;
&amp;lt;%@ &lt;b&gt;taglib&lt;/b&gt; uri="http://java.sun.com/jsp/jstl/core
"
         prefix="c" %&amp;gt;
&amp;lt;%@ &lt;b&gt;taglib&lt;/b&gt; uri="/functions" prefix="f" %&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Localized Dates&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;
&amp;lt;body bgcolor="white"&amp;gt;
&amp;lt;&lt;b&gt;jsp:useBean&lt;/b&gt; id="locales" scope="application"
    class="mypkg.MyLocales"/&amp;gt;

&amp;lt;form name="localeForm" action="index.jsp" method="post"&amp;gt;
&amp;lt;&lt;b&gt;c:set&lt;/b&gt; var="selectedLocaleString" value="&lt;b&gt;${param.locale}&lt;/b&gt;" /&amp;gt;
&amp;lt;&lt;b&gt;c:set&lt;/b&gt; var="selectedFlag"
     value="&lt;b&gt;${!empty selectedLocaleString}&lt;/b&gt;" /&amp;gt;
&amp;lt;b&amp;gt;Locale:&amp;lt;/b&amp;gt;
&amp;lt;select name=locale&amp;gt;
&amp;lt;&lt;b&gt;c:forEach&lt;/b&gt; var="localeString" items="&lt;b&gt;${locales.localeNames}&lt;/b&gt;" &amp;gt;
&amp;lt;&lt;b&gt;c:choose&lt;/b&gt;&amp;gt;
    &amp;lt;&lt;b&gt;c:when&lt;/b&gt; test="&lt;b&gt;${selectedFlag}&lt;/b&gt;"&amp;gt;
        &amp;lt;&lt;b&gt;c:choose&lt;/b&gt;&amp;gt;
            &amp;lt;&lt;b&gt;c:when&lt;/b&gt;
                 test="&lt;b&gt;${f:equals(selectedLocaleString, localeString)}&lt;/b&gt;" &amp;gt;
                &amp;lt;option selected&amp;gt;&lt;b&gt;${localeString}&lt;/b&gt;&amp;lt;/option&amp;gt;
            &amp;lt;/c:when&amp;gt;
            &amp;lt;c:otherwise&amp;gt;
                &amp;lt;option&amp;gt;&lt;b&gt;${localeString}&lt;/b&gt;&amp;lt;/option&amp;gt;
            &amp;lt;/c:otherwise&amp;gt;
        &amp;lt;/c:choose&amp;gt;
    &amp;lt;/c:when&amp;gt;
    &amp;lt;&lt;b&gt;c:otherwise&lt;/b&gt;&amp;gt;
        &amp;lt;option&amp;gt;&lt;b&gt;${localeString}&lt;/b&gt;&amp;lt;/option&amp;gt;
    &amp;lt;/c:otherwise&amp;gt;
&amp;lt;/c:choose&amp;gt;
&amp;lt;/c:forEach&amp;gt;
&amp;lt;/select&amp;gt;
&amp;lt;input type="submit" name="Submit" value="Get Date"&amp;gt;
&amp;lt;/form&amp;gt;

&amp;lt;&lt;b&gt;c:if&lt;/b&gt; test="${selectedFlag}" &amp;gt;
    &amp;lt;&lt;b&gt;jsp:setProperty&lt;/b&gt; name="locales"
        property="selectedLocaleString"
        value="&lt;b&gt;${selectedLocaleString}&lt;/b&gt;" /&amp;gt;
    &amp;lt;&lt;b&gt;jsp:useBean&lt;/b&gt; id="date" class="mypkg.MyDate"/&amp;gt;
    &amp;lt;&lt;b&gt;jsp:setProperty&lt;/b&gt; name="date" property="locale"
        value="&lt;b&gt;${locales.selectedLocale}&lt;/b&gt;"/&amp;gt;
    &amp;lt;b&amp;gt;Date: &amp;lt;/b&amp;gt;&lt;b&gt;${date.date}&lt;/b&gt;&amp;lt;/c:if&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;p&gt;To deploy the &lt;tt&gt;date&lt;/tt&gt; application with NetBeans IDE, follow these steps:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Start the Application Server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In NetBeans IDE, select File&amp;#8594;Open Project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Open Project dialog, navigate to:&lt;/p&gt;&lt;pre&gt;&lt;i&gt;tut-install&lt;/i&gt;/javaeetutorial5/examples/web/&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the &lt;tt&gt;date&lt;/tt&gt; folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the Open as Main Project check box.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Open Project Folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Projects tab, right-click the &lt;tt&gt;date&lt;/tt&gt; project, and select Deploy Project.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;To deploy the &lt;tt&gt;date&lt;/tt&gt; application with the Ant tool, follow these steps:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;In a terminal window, go to &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/date/&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type &lt;tt&gt;&lt;b&gt;ant&lt;/b&gt;&lt;/tt&gt;. This command will spawn any necessary compilations, copy files to the &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/date/build/&lt;/tt&gt; directory, and create a WAR file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start the Application Server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type &lt;tt&gt;&lt;b&gt;ant deploy&lt;/b&gt;&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;To run the example, do the following:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Set the character encoding in your browser to UTF-8.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open your browser to &lt;tt&gt;http://localhost:8080/date&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You will see a combo box whose entries are locales.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=44024696421&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>The Example JSP Pages</title><link>http://www.softxml.com/LearnTutorial.asp?id=46178730218&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;To illustrate JSP technology, this chapter rewrites each servlet in the Duke’s Bookstore
application introduced in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaff.html"&gt;The Example Servlets&lt;/a&gt; as a JSP page (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahb.html#bnahc"&gt;Table 5-1&lt;/a&gt;).&lt;/p&gt;&lt;a name="bnahc"&gt;&lt;/a&gt;&lt;h6&gt;Table 5-1 Duke’s Bookstore Example JSP Pages&lt;/h6&gt;&lt;table ID="Table1"&gt;&lt;col width="171*"&gt;&lt;col width="179*"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th align="left" valign="top"&gt;&lt;p&gt;Function&lt;/p&gt;&lt;/th&gt;
&lt;th align="left" valign="top"&gt;&lt;p&gt;JSP Pages&lt;/p&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Enter the
bookstore.&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;bookstore.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Create the bookstore banner.&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;banner.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Browse the books offered for sale.&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;bookcatalog.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Add a book to
the shopping cart.&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;bookcatalog.jsp&lt;/tt&gt; and &lt;tt&gt;bookdetails.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Get detailed information on a specific book.&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;bookdetails.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Display the
shopping cart.&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;bookshowcart.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Remove one or more books from the shopping cart.&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;bookshowcart.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Buy the books
in the shopping cart.&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;bookcashier.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" valign="top"&gt;&lt;p&gt;Receive an acknowledgment for the purchase.&lt;/p&gt;&lt;/td&gt;
&lt;td align="left" valign="top"&gt;&lt;p&gt;&lt;tt&gt;bookreceipt.jsp&lt;/tt&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;The data for the bookstore application is still maintained in a database and
is accessed through &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore2/src/java/com/sun/bookstore2/database/BookDBAO.java&lt;/tt&gt;. However, the JSP pages access &lt;tt&gt;BookDBAO&lt;/tt&gt; through the JavaBeans
component &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore2/src/java/com/sun/bookstore2/database/BookDB.java&lt;/tt&gt;. This class allows the JSP pages to use JSP elements
designed to work with JavaBeans components (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnair.html#bnais"&gt;JavaBeans Component Design Conventions&lt;/a&gt;).&lt;/p&gt;&lt;p&gt;The implementation of the database bean follows. The bean has two instance variables:
the current book and the data access object.&lt;/p&gt;&lt;pre&gt;package database;
public class BookDB {
    private String bookId = "0";
    private BookDBAO database = null;

    public BookDB () throws Exception {
    }
    public void setBookId(String bookId) {
        this.bookId = bookId;
    }
    public void setDatabase(BookDAO database) {
        this.database = database;
    }
    public Book getBook()
         throws Exception {
        return (Book)database.getBook(bookId);
    }
    ...
}&lt;/pre&gt;&lt;p&gt;&lt;a name="indexterm-314"&gt;&lt;/a&gt;&lt;a name="indexterm-315"&gt;&lt;/a&gt;This version of the Duke’s Bookstore application is organized along the Model-View-Controller (MVC)
architecture. The MVC architecture is a widely used architectural approach for interactive applications
that distributes functionality among application objects so as to minimize the degree of
coupling between the objects. To achieve this, it divides applications into three layers: model,
view, and controller. Each layer handles specific tasks and has responsibilities to the
other layers:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;The &lt;b&gt;model&lt;/b&gt; represents business data, along with
business logic or operations that govern access and modification of
this business data. The model notifies views when it changes and lets
the view query the model about its state. It also lets the controller
access application functionality encapsulated by the model. In the
Duke’s Bookstore application, the shopping cart and database access
object contain the business logic for the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;b&gt;view&lt;/b&gt; renders the contents of a model. It gets data
from the model and specifies how that data should be presented. It
updates data presentation when the model changes. A view also forwards
user input to a controller. The Duke’s Bookstore JSP pages format the
data stored in the session-scoped shopping cart and the page-scoped
database bean.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;b&gt;controller&lt;/b&gt; defines application behavior. It
dispatches user requests and selects views for presentation. It
interprets user inputs and maps them into actions to be performed by
the model. In a web application, user inputs are HTTP &lt;tt&gt;GET&lt;/tt&gt; and &lt;tt&gt;POST&lt;/tt&gt;
requests. A controller selects the next view to display based on the
user interactions and the outcome of the model operations. In the
Duke’s Bookstore application, the &lt;tt&gt;Dispatcher&lt;/tt&gt; servlet is the
controller. It examines the request URL, creates and initializes a
session-scoped JavaBeans component (the shopping cart), and dispatches
requests to view JSP pages.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;hr&gt;&lt;p&gt;&lt;b&gt;Note - &lt;/b&gt;When employed in a web application, the MVC architecture is often referred to
as a Model-2 architecture. The bookstore example discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafd.html"&gt;Chapter 4, Java Servlet Technology&lt;/a&gt;, which intermixes presentation
and business logic, follows what is known as a Model-1 architecture. The Model-2
architecture is the recommended approach to designing web applications.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;a name="indexterm-316"&gt;&lt;/a&gt;In addition, this version of the application uses several custom tags from the
JavaServer Pages Standard Tag Library (JSTL), described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnakc.html"&gt;Chapter 7, JavaServer Pages Standard Tag Library&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;tt&gt;c:if&lt;/tt&gt;, &lt;tt&gt;c:choose&lt;/tt&gt;, &lt;tt&gt;c:when&lt;/tt&gt;, and &lt;tt&gt;c:otherwise&lt;/tt&gt; for flow control&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;c:set&lt;/tt&gt; for setting scoped variables&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;c:url&lt;/tt&gt; for encoding URLs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;fmt:message&lt;/tt&gt;, &lt;tt&gt;fmt:formatNumber&lt;/tt&gt;, and &lt;tt&gt;fmt:formatDate&lt;/tt&gt; for providing locale-sensitive messages, numbers, and dates&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Custom tags are the preferred mechanism for performing a wide variety of dynamic
processing tasks, including accessing databases, using enterprise services such as email and directories,
and implementing flow control. In earlier versions of JSP technology, such tasks were
performed with JavaBeans components in conjunction with scripting elements (discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaon.html"&gt;Chapter 9, Scripting in JSP Pages&lt;/a&gt;). Although still
available in JSP 2.0 technology, scripting elements tend to make JSP pages more
difficult to maintain because they mix presentation and logic, something that is discouraged
in page design. Custom tags are introduced in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaiy.html"&gt;Using Custom Tags&lt;/a&gt; and described in
detail in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnalj.html"&gt;Chapter 8, Custom Tags in JSP Pages&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Finally, this version of the example contains an applet to generate a dynamic
digital clock in the banner. See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaje.html"&gt;Including an Applet&lt;/a&gt; for a description of the
JSP element that generates HTML for downloading the applet.&lt;/p&gt;&lt;p&gt;To deploy and run the application using NetBeans IDE, follow these steps:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Perform all the operations described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaez.html"&gt;Accessing Databases from Web Applications&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In NetBeans IDE, select File&amp;#8594;Open Project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Open Project dialog, navigate to:&lt;/p&gt;&lt;pre&gt;&lt;i&gt;tut-install&lt;/i&gt;/javaeetutorial5/examples/web/&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the &lt;tt&gt;bookstore2&lt;/tt&gt; folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the Open as Main Project check box and the Open Required Projects check box.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Open Project Folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Projects tab, right-click the &lt;tt&gt;bookstore2&lt;/tt&gt; project, and select Deploy Project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To run the application, open the bookstore URL &lt;tt&gt;http://localhost:8080/bookstore2/books/bookstore&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;To deploy and run the application using Ant, follow these steps:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;In a terminal window, go to &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore2/&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type &lt;tt&gt;&lt;b&gt;ant&lt;/b&gt;&lt;/tt&gt;. This command will spawn any necessary compilations, copy files to the &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore2/build/&lt;/tt&gt; directory, and create a WAR file and copy it to the &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore2/dist/&lt;/tt&gt; directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start the Application Server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Perform all the operations described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaez.html#bnafb"&gt;Creating a Data Source in the Application Server&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To deploy the example, type &lt;tt&gt;&lt;b&gt;ant deploy&lt;/b&gt;&lt;/tt&gt;. The deploy target outputs a URL for running the application. Ignore this URL, and instead use the one shown in the next step.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To run the application, open the bookstore URL &lt;tt&gt;http://localhost:8080/bookstore2/books/bookstore&lt;/tt&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;To learn how to configure the example, refer to the deployment descriptor (the
&lt;tt&gt;web.xml&lt;/tt&gt; file), which includes the following configurations:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;A &lt;tt&gt;display-name&lt;/tt&gt; element that specifies the name that tools use to identify the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A &lt;tt&gt;context-param&lt;/tt&gt; element that specifies the JSTL resource bundle base name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A &lt;tt&gt;listener&lt;/tt&gt; element that identifies the &lt;tt&gt;ContextListener&lt;/tt&gt; class used to create and remove the database access.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A &lt;tt&gt;servlet&lt;/tt&gt; element that identifies the &lt;tt&gt;Dispatcher&lt;/tt&gt; servlet instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A set of &lt;tt&gt;servlet-mapping&lt;/tt&gt; elements that map &lt;tt&gt;Dispatcher&lt;/tt&gt; to URL patterns for each of the JSP pages in the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nested inside a &lt;tt&gt;jsp-config&lt;/tt&gt; element are two &lt;tt&gt;jsp-property-group&lt;/tt&gt; elements, which define the preludes and coda to be included in each page. See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnajg.html"&gt;Setting Properties for Groups of JSP Pages&lt;/a&gt; for more information.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahb.html#bnahd"&gt;Figure 5-2&lt;/a&gt; shows the &lt;tt&gt;bookcatalog.jsp&lt;/tt&gt; page from the Duke’s Bookstore application. This page
displays a list of all the books that are available for purchase.&lt;/p&gt;&lt;a name="bnahd"&gt;&lt;/a&gt;&lt;h6&gt;Figure 5-2 Book Catalog&lt;/h6&gt;&lt;img src="http://java.sun.com/javaee/5/docs/tutorial/doc/figures/web-bookCatalog1.gif" alt="Screen capture of Duke&amp;#8216;s Bookstore book catalog, with titles, authors, prices, and " add="" cart="" links.="" titles="" are="" links="" to="" book="" details.="" height="867" width="662"&gt;&lt;p&gt;See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaff.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=46178730218&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>The Life Cycle of a JSP Page</title><link>http://www.softxml.com/LearnTutorial.asp?id=45835389705&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;A JSP page services requests as a servlet. Thus, the life cycle and
many of the capabilities of JSP pages (in particular the dynamic aspects) are
determined by Java Servlet technology. You will notice that many sections in this
chapter refer to classes and methods described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafd.html"&gt;Chapter 4, Java Servlet Technology&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-318"&gt;&lt;/a&gt;&lt;a name="indexterm-319"&gt;&lt;/a&gt;When a request is mapped to a JSP page, the web container first
checks whether the JSP page’s servlet is older than the JSP page. If
the servlet is older, the web container translates the JSP page into a
servlet class and compiles the class. During development, one of the advantages of
JSP pages over servlets is that the build process is performed automatically.&lt;/p&gt;

&lt;a name="bnahf"&gt;&lt;/a&gt;&lt;h4&gt;Translation and Compilation&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-320"&gt;&lt;/a&gt;During the translation phase each type of data in a JSP page is
treated differently. Static data is transformed into code that will emit the data
into the response stream. JSP elements are treated as follows:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-321"&gt;&lt;/a&gt;Directives are used to control how the web container translates and executes the JSP page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scripting elements are inserted into the JSP page’s servlet class. See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaon.html"&gt;Chapter 9, Scripting in JSP Pages&lt;/a&gt; for details.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expression language expressions are passed as parameters to calls to the JSP expression evaluator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;jsp:[set|get]Property&lt;/tt&gt; elements are converted into method calls to JavaBeans components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;tt&gt;jsp:[include|forward]&lt;/tt&gt;elements are converted into invocations of the Java Servlet API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;tt&gt;jsp:plugin&lt;/tt&gt; element is converted into browser-specific markup for activating an applet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom tags are converted into calls to the tag handler that implements the custom tag.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;In the Application Server, the source for the servlet created from a JSP
page named &lt;i&gt;pageName&lt;/i&gt; is in this file:&lt;/p&gt;&lt;pre&gt;&lt;i&gt;domain-dir&lt;/i&gt;/generated/jsp/j2ee-modules/&lt;i&gt;WAR-NAME&lt;/i&gt;/&lt;i&gt;pageName&lt;/i&gt;_jsp.java&lt;/pre&gt;&lt;p&gt;For example, the source for the index page (named &lt;tt&gt;index.jsp&lt;/tt&gt;) for the &lt;tt&gt;date&lt;/tt&gt;
localization example discussed at the beginning of the chapter would be named:&lt;/p&gt;&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;i&gt;domain-dir&lt;/i&gt;&lt;tt&gt;/generated/jsp/j2ee-modules/date/index_jsp.java&lt;/tt&gt;&lt;/pre&gt;&lt;p&gt;&lt;a name="indexterm-322"&gt;&lt;/a&gt;&lt;a name="indexterm-323"&gt;&lt;/a&gt;Both the translation and the compilation phases can yield errors that are observed
only when the page is requested for the first time. If an error
is encountered during either phase, the server will return &lt;tt&gt;JasperException&lt;/tt&gt; and a message
that includes the name of the JSP page and the line where the
error occurred.&lt;/p&gt;&lt;p&gt;After the page has been translated and compiled, the JSP page’s servlet (for
the most part) follows the servlet life cycle described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafi.html"&gt;Servlet Life Cycle&lt;/a&gt;:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;If an instance of the JSP page’s servlet does not exist, the container:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;p&gt;Loads the JSP page’s servlet class&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Instantiates an instance of the servlet class&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initializes the servlet instance by calling the &lt;tt&gt;jspInit&lt;/tt&gt; method&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The container invokes the &lt;tt&gt;_jspService&lt;/tt&gt; method, passing request and response objects.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;If the container needs to remove the JSP page’s servlet, it calls the
&lt;tt&gt;jspDestroy&lt;/tt&gt; method.&lt;/p&gt;

&lt;a name="bnahg"&gt;&lt;/a&gt;&lt;h4&gt;Execution&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-324"&gt;&lt;/a&gt;&lt;a name="indexterm-325"&gt;&lt;/a&gt;You can control various JSP page execution parameters by using &lt;tt&gt;page&lt;/tt&gt; directives. The
directives that pertain to buffering output and handling errors are discussed here. Other
directives are covered in the context of specific page-authoring tasks throughout the chapter.&lt;/p&gt;

&lt;a name="bnahh"&gt;&lt;/a&gt;&lt;h5&gt;Buffering&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-326"&gt;&lt;/a&gt;When a JSP page is executed, output written to the response object is
automatically buffered. You can set the size of the buffer using the
following page directive:&lt;/p&gt;&lt;pre&gt;&amp;lt;%@ page buffer="none|&lt;i&gt;xxx&lt;/i&gt;kb" %&amp;gt;&lt;/pre&gt;&lt;p&gt;A larger buffer allows more content to be written before anything is actually
sent back to the client, thus providing the JSP page with more
time to set appropriate status codes and headers or to forward to another
web resource. A smaller buffer decreases server memory load and allows the client
to start receiving data more quickly.&lt;/p&gt;

&lt;a name="bnahi"&gt;&lt;/a&gt;&lt;h5&gt;Handling JSP Page Errors&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-327"&gt;&lt;/a&gt;Any number of exceptions can arise when a JSP page is executed. To
specify that the web container should forward control to an error page if
an exception occurs, include the following &lt;tt&gt;page&lt;/tt&gt; directive at the beginning of
your JSP page:&lt;/p&gt;&lt;pre&gt;&amp;lt;%@ page errorPage="&lt;i&gt;file-name&lt;/i&gt;" %&amp;gt;&lt;/pre&gt;&lt;p&gt;The Duke’s Bookstore application page &lt;tt&gt;&lt;/tt&gt;&lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore2/web/template/preludeErrorPage.jspf&lt;/tt&gt; contains the directive:&lt;/p&gt;&lt;pre&gt;&amp;lt;%@ page errorPage="errorpage.jsp"%&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;a name="indexterm-328"&gt;&lt;/a&gt;The following page directive at the beginning of &lt;i&gt;tut-install&lt;/i&gt;&lt;tt&gt;/javaeetutorial5/examples/web/bookstore2/web/error/errorpage.jsp&lt;/tt&gt; indicates that it is
serving as an error page:&lt;/p&gt;&lt;pre&gt;&amp;lt;%@ page isErrorPage="true" %&amp;gt;&lt;/pre&gt;&lt;p&gt;This directive makes an object of type &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/jsp/ErrorData.html"&gt;javax.servlet.jsp.ErrorData&lt;/a&gt; available to the error
page so that you can retrieve, interpret, and possibly display information about the cause
of the exception in the error page. You access the error data
object in an EL (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html"&gt;Unified Expression Language&lt;/a&gt;) expression by way of the page context. Thus,
&lt;tt&gt;${pageContext.errorData.statusCode}&lt;/tt&gt; retrieves the status code, and &lt;tt&gt;${pageContext.errorData.throwable}&lt;/tt&gt; retrieves the exception. You can
retrieve the cause of the exception using this expression:&lt;/p&gt;&lt;pre&gt;${pageContext.errorData.throwable.cause}&lt;/pre&gt;&lt;p&gt;For example, the error page for Duke’s Bookstore is as follows:&lt;/p&gt;&lt;pre&gt;&amp;lt;%@ page isErrorPage="true" %&amp;gt;
&amp;lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core"
     prefix="c" %&amp;gt;
&amp;lt;%@ taglib uri="http://java.sun.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=45835389705&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Creating Static Content</title><link>http://www.softxml.com/LearnTutorial.asp?id=4363602955&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;You create static content in a JSP page simply by writing it
as if you were creating a page that consisted only of that content.
Static content can be expressed in any text-based format, such as HTML, Wireless
Markup Language (WML), and XML. The default format is HTML. If you want
to use a format other than HTML, at the beginning of your JSP
page you include a &lt;tt&gt;page&lt;/tt&gt; directive with the &lt;tt&gt;contentType&lt;/tt&gt; attribute set to the
content type. The purpose of the &lt;tt&gt;contentType&lt;/tt&gt; directive is to allow the browser to
correctly interpret the resulting content. So if you wanted a page to contain
data expressed in WML, you would include the following directive:&lt;/p&gt;&lt;pre&gt;&amp;lt;%@ page contentType="text/vnd.wap.wml"%&amp;gt;&lt;/pre&gt;&lt;p&gt;A registry of content type names is kept by the IANA at
&lt;a href="http://www.iana.org/assignments/media-types/"&gt;http://www.iana.org/assignments/media-types/&lt;/a&gt;.&lt;/p&gt;

&lt;a name="bnahk"&gt;&lt;/a&gt;&lt;h4&gt;Response and Page Encoding&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-332"&gt;&lt;/a&gt;You also use the &lt;tt&gt;contentType&lt;/tt&gt; attribute to specify the encoding of the response.
For example, the date application specifies that the page should be encoded using
UTF-8, an encoding that supports almost all locales, using the following &lt;tt&gt;page&lt;/tt&gt; directive:&lt;/p&gt;&lt;pre&gt;&amp;lt;%@ page contentType="text/html; charset=UTF-8" %&amp;gt;&lt;/pre&gt;&lt;p&gt;If the response encoding weren’t set, the localized dates would not be rendered
correctly.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=4363602955&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Creating Dynamic Content</title><link>http://www.softxml.com/LearnTutorial.asp?id=22726536186&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;You create dynamic content by accessing Java programming language object properties.&lt;/p&gt;

&lt;a name="bnahm"&gt;&lt;/a&gt;&lt;h4&gt;Using Objects within JSP Pages&lt;/h4&gt;
&lt;p&gt;You can access a variety of objects, including enterprise beans and JavaBeans components,
within a JSP page. JSP technology automatically makes some objects available, and you
can also create and access application-specific objects.&lt;/p&gt;

&lt;a name="bnahn"&gt;&lt;/a&gt;&lt;h5&gt;Using Implicit Objects&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-335"&gt;&lt;/a&gt;&lt;b&gt;Implicit objects&lt;/b&gt; are created by the web container and contain information related to a
particular request, page, session, or application. Many of the objects are defined by
the Java servlet technology underlying JSP technology and are discussed at length in
&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafd.html"&gt;Chapter 4, Java Servlet Technology&lt;/a&gt;. The section &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaij"&gt;Implicit Objects&lt;/a&gt; explains how you access implicit objects using the JSP
expression language.&lt;/p&gt;

&lt;a name="bnaho"&gt;&lt;/a&gt;&lt;h5&gt;Using Application-Specific Objects&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-336"&gt;&lt;/a&gt;When possible, application behavior should be encapsulated in objects so that page designers
can focus on presentation issues. Objects can be created by developers who are
proficient in the Java programming language and in accessing databases and other services.
The main way to create and use application-specific objects within a JSP page
is to use JSP standard tags (discussed in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnair.html"&gt;JavaBeans Components&lt;/a&gt;) to create JavaBeans components
and set their properties, and EL expressions to access their properties. You can
also access JavaBeans components and other objects in scripting elements, which are described
in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaon.html"&gt;Chapter 9, Scripting in JSP Pages&lt;/a&gt;.&lt;/p&gt;

&lt;a name="bnahp"&gt;&lt;/a&gt;&lt;h5&gt;Using Shared Objects&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-337"&gt;&lt;/a&gt;The conditions affecting concurrent access to shared objects (described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnafo.html#bnafs"&gt;Controlling Concurrent Access to Shared Resources&lt;/a&gt;) apply to objects
accessed from JSP pages that run as multithreaded servlets. You can use the
following &lt;tt&gt;page&lt;/tt&gt; directive to indicate how a web container should dispatch multiple client
requests:&lt;/p&gt;&lt;pre&gt;&amp;lt;%@ page isThreadSafe="true|false" %&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;a name="indexterm-338"&gt;&lt;/a&gt;When the &lt;tt&gt;isThreadSafe&lt;/tt&gt; attribute is set to &lt;tt&gt;true&lt;/tt&gt;, the web container can
choose to dispatch multiple concurrent client requests to the JSP page. This is
the &lt;b&gt;default&lt;/b&gt; setting. If using &lt;tt&gt;true&lt;/tt&gt;, you must ensure that you properly synchronize access
to any shared objects defined at the page level. This includes objects created
within declarations, JavaBeans components with page scope, and attributes of the page context
object (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaij"&gt;Implicit Objects&lt;/a&gt;).&lt;/p&gt;&lt;p&gt;If &lt;tt&gt;isThreadSafe&lt;/tt&gt; is set to &lt;tt&gt;false&lt;/tt&gt;, requests are dispatched one at a time
in the order they were received, and access to page-level objects does not
have to be controlled.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=22726536186&amp;f=javatme&amp;fo=tutorials</guid><category>javatme</category></item><item><title>Unified Expression Language</title><link>http://www.softxml.com/LearnTutorial.asp?id=3357474161&amp;f=javatme&amp;fo=tutorials</link><description>&lt;p&gt;The primary new feature of JSP 2.1 is the unified expression language (unified EL),
which represents a union of the expression language offered by JSP 2.0 and
the expression language created for JavaServer Faces technology (see &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaph.html"&gt;Chapter 10, JavaServer Faces Technology&lt;/a&gt;) version 1.0.&lt;/p&gt;&lt;p&gt;The expression language introduced in JSP 2.0 allows page authors to use simple
expressions to dynamically read data from JavaBeans components. For example, the &lt;tt&gt;test&lt;/tt&gt; attribute
of the following conditional tag is supplied with an EL expression that compares
the number of items in the session-scoped bean named &lt;tt&gt;cart&lt;/tt&gt; with 0.&lt;/p&gt;&lt;pre&gt;&amp;lt;c:if test="${sessionScope.cart.numberOfItems &amp;gt; 0}"&amp;gt;
  ...
&amp;lt;/c:if&amp;gt;&lt;/pre&gt;&lt;p&gt;As explained in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahe.html"&gt;The Life Cycle of a JSP Page&lt;/a&gt;, JSP supports a simple request/response life cycle, during which
a page is executed and the HTML markup is rendered immediately. Therefore, the
simple, read-only expression language offered by JSP 2.0 was well suited to the
needs of JSP applications.&lt;/p&gt;&lt;p&gt;&lt;a name="indexterm-340"&gt;&lt;/a&gt;JavaServer Faces technology, on the other hand, features a multiphase life cycle designed to
support its sophisticated UI component model, which allows for converting and validating component
data, propagating component data to objects, and handling component events. To facilitate these
functions, JavaServer Faces technology introduced its own expression language that included the following functionality:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Deferred evaluation of expressions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The ability to set data as well as get data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The ability to invoke methods&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaqm.html#bnaqp"&gt;Using the Unified EL to Reference Backing Beans&lt;/a&gt; for more information on how to use the unified EL
in JavaServer Faces applications.&lt;/p&gt;&lt;p&gt;These two expression languages have been unified for a couple reasons. One reason
is so that page authors can mix JSP content with JavaServer Faces tags
without worrying about conflicts caused by the different life cycles these technologies support.
Another reason is so that other JSP-based technologies could make use of the
additional features similarly to the way JavaServer Faces technology uses them. In fact,
although the standard JSP tags and static content continue to use only those
features present in JSP 2.0, authors of JSP custom tags can create tags
that take advantage of the new set of features in the unified expression
language.&lt;/p&gt;&lt;p&gt;To summarize, the new, unified expression language allows page authors to use simple
expressions to perform the following tasks:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;Dynamically read application data stored in JavaBeans components, various data structures, and implicit objects&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamically write data, such as user input into forms, to JavaBeans components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Invoke arbitrary static and public methods&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamically perform arithmetic operations&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The unified EL also allows custom tag developers to specify which of the
following kinds of expressions that a custom tag attribute will accept:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-341"&gt;&lt;/a&gt;&lt;a name="indexterm-342"&gt;&lt;/a&gt;&lt;b&gt;Immediate evaluation expressions&lt;/b&gt; or &lt;b&gt;deferred evaluation expressions&lt;/b&gt;.
An immediate evaluation expression is evaluated immediately by the JSP
engine. A deferred evaluation expression can be evaluated later by the
underlying technology using the expression language.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-343"&gt;&lt;/a&gt;&lt;a name="indexterm-344"&gt;&lt;/a&gt;&lt;b&gt;Value expression&lt;/b&gt; or &lt;b&gt;method expression&lt;/b&gt;. A value expression references data, whereas a method expression invokes a method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a name="indexterm-345"&gt;&lt;/a&gt;&lt;a name="indexterm-346"&gt;&lt;/a&gt;&lt;b&gt;Rvalue expression&lt;/b&gt; or &lt;b&gt;Lvalue expression&lt;/b&gt;.
An rvalue expression can only read a value, whereas an lvalue
expression can both read and write that value to an external object.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Finally, the unified EL also provides a pluggable API for resolving expressions so
that application developers can implement their own resolvers that can handle expressions not
already supported by the unified EL.&lt;/p&gt;&lt;p&gt;This section gives an overview of the unified expression language features by explaining
the following topics:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnahr"&gt;Immediate and Deferred Evaluation Syntax&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnahu"&gt;Value and Method Expressions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaia"&gt;Defining a Tag Attribute Type&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaic"&gt;Deactivating Expression Evaluation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaid"&gt;Literal Expressions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaif"&gt;Resolving Expressions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaij"&gt;Implicit Objects&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaik"&gt;Operators&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnail"&gt;Reserved Words&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaim"&gt;Examples of EL Expressions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaio"&gt;Functions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;


&lt;a name="bnahr"&gt;&lt;/a&gt;&lt;h4&gt;Immediate and Deferred Evaluation Syntax&lt;/h4&gt;
&lt;p&gt;&lt;a name="indexterm-347"&gt;&lt;/a&gt;&lt;a name="indexterm-348"&gt;&lt;/a&gt;The unified EL supports both immediate and deferred evaluation of expressions. &lt;b&gt;Immediate evaluation&lt;/b&gt; means
that the JSP engine evaluates the expression and returns the result immediately when
the page is first rendered. &lt;b&gt;Deferred evaluation&lt;/b&gt; means that the technology using the expression language
can employ its own machinery to evaluate the expression sometime later during the
page’s life cycle, whenever it is appropriate to do so.&lt;/p&gt;&lt;p&gt;Those expressions that are evaluated immediately use the &lt;tt&gt;${}&lt;/tt&gt; syntax, which was introduced
with the JSP 2.0 expression language. Expressions whose evaluation is deferred use the
&lt;tt&gt;#{}&lt;/tt&gt; syntax, which was introduced by JavaServer Faces technology.&lt;/p&gt;&lt;p&gt;Because of its multiphase life cycle, JavaServer Faces technology uses deferred evaluation expressions.
During the life cycle, component events are handled, data is validated, and other
tasks are performed, all done in a particular order. Therefore, it must defer
evaluation of expressions until the appropriate point in the life cycle.&lt;/p&gt;&lt;p&gt;Other technologies using the unified EL might have different reasons for using deferred
expressions.&lt;/p&gt;

&lt;a name="bnahs"&gt;&lt;/a&gt;&lt;h5&gt;Immediate Evaluation&lt;/h5&gt;
&lt;p&gt;All expressions using the &lt;tt&gt;${}&lt;/tt&gt; syntax are evaluated immediately. These expressions can only
be used within template text or as the value of a JSP tag
attribute that can accept runtime expressions.&lt;/p&gt;&lt;p&gt;The following example shows a tag whose value attribute references an immediate evaluation
expression that gets the total price from the session-scoped bean named cart:&lt;/p&gt;&lt;pre&gt;&amp;lt;fmt:formatNumber value="${sessionScope.cart.total}"/&amp;gt;&lt;/pre&gt;&lt;p&gt;The JSP engine evaluates the expression, &lt;tt&gt;${sessionScope.cart.total}&lt;/tt&gt;, converts it, and passes the
returned value to the tag handler.&lt;/p&gt;&lt;p&gt;Immediate evaluation expressions are always read-only value expressions. The expression shown above can
only get the total price from the cart bean; it cannot set the
total price.&lt;/p&gt;

&lt;a name="bnaht"&gt;&lt;/a&gt;&lt;h5&gt;Deferred Evaluation&lt;/h5&gt;
&lt;p&gt;Deferred evaluation expressions take the form &lt;tt&gt;#{expr}&lt;/tt&gt; and can be evaluated at other
phases of a page life cycle as defined by whatever technology is using
the expression. In the case of JavaServer Faces technology, its controller can evaluate
the expression at different phases of the life cycle depending on how the
expression is being used in the page.&lt;/p&gt;&lt;p&gt;The following example shows a JavaServer Faces &lt;tt&gt;inputText&lt;/tt&gt; tag, which represents a text
field component into which a user enters a value. The &lt;tt&gt;inputText&lt;/tt&gt; tag’s &lt;tt&gt;value&lt;/tt&gt;
attribute references a deferred evaluation expression that points to the &lt;tt&gt;name&lt;/tt&gt; property of the
&lt;tt&gt;customer&lt;/tt&gt; bean.&lt;/p&gt;&lt;pre&gt;&amp;lt;h:inputText id="name" value="#{customer.name}" /&amp;gt;&lt;/pre&gt;&lt;p&gt;For an initial request of the page containing this tag, the JavaServer Faces
implementation evaluates the &lt;tt&gt;#{customer.name}&lt;/tt&gt; expression during the render response phase of the life
cycle. During this phase, the expression merely accesses the value of &lt;tt&gt;name&lt;/tt&gt; from
the &lt;tt&gt;customer&lt;/tt&gt; bean, as is done in immediate evaluation.&lt;/p&gt;&lt;p&gt;For a postback, the JavaServer Faces implementation evaluates the expression at different phases
of the life cycle, during which the value is retrieved from the request,
validated, and propagated to the &lt;tt&gt;customer&lt;/tt&gt; bean.&lt;/p&gt;&lt;p&gt;As shown in this example, deferred evaluation expressions can be value expressions that
can be used to both read and write data. They can also
be method expressions. Value expressions (both immediate and deferred) and method expressions are explained
in the next section.&lt;/p&gt;

&lt;a name="bnahu"&gt;&lt;/a&gt;&lt;h4&gt;Value and Method Expressions&lt;/h4&gt;
&lt;p&gt;The unified EL defines two kinds of expressions: value expressions and method expressions.
Value expressions can either yield a value or set a value. Method expressions
reference methods that can be invoked and can return a value.&lt;/p&gt;

&lt;a name="bnahv"&gt;&lt;/a&gt;&lt;h5&gt;Value Expressions&lt;/h5&gt;
&lt;p&gt;&lt;a name="indexterm-349"&gt;&lt;/a&gt;&lt;a name="indexterm-350"&gt;&lt;/a&gt;&lt;a name="indexterm-351"&gt;&lt;/a&gt;Value expressions can be further categorized into rvalue and lvalue expressions. &lt;b&gt;Rvalue expressions&lt;/b&gt; are
those that can read data, but cannot write it. &lt;b&gt;Lvalue expressions&lt;/b&gt; can both read and
write data.&lt;/p&gt;&lt;p&gt;All expressions that are evaluated immediately use the &lt;tt&gt;${}&lt;/tt&gt; delimiters and are always
rvalue expressions. Expressions whose evaluation can be deferred use the &lt;tt&gt;#{}&lt;/tt&gt; delimiters and
can act as both rvalue and lvalue expressions. Consider these two value expressions:&lt;/p&gt;&lt;pre&gt;&amp;lt;taglib:tag value="${customer.name}" /&amp;gt;
&amp;lt;taglib:tag value="#{customer.name}" /&amp;gt;&lt;/pre&gt;&lt;p&gt;The former uses immediate evaluation syntax, whereas the latter uses deferred evaluation syntax.
The first expression accesses the &lt;tt&gt;name&lt;/tt&gt; property, gets its value, and the value
is added to the response and rendered on the page. The same thing
can happen with the second expression. However, the tag handler can defer the
evaluation of this expression to a later time in the page life cycle,
if the technology using this tag allows it.&lt;/p&gt;&lt;p&gt;In the case of JavaServer Faces technology, the latter tag’s expression is evaluated
immediately during an initial request for the page. In this case, this expression
acts as an rvalue expression. During a postback, this expression can be used
to set the value of the &lt;tt&gt;name&lt;/tt&gt; property with user input. In this
situation, the expression acts as an lvalue expression.&lt;/p&gt;

&lt;a name="bnahw"&gt;&lt;/a&gt;&lt;h5&gt;Referencing Objects Using Value Expressions&lt;/h5&gt;
&lt;p&gt;Both rvalue and lvalue expressions can refer to the following objects and their
properties or attributes:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;JavaBeans components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Collections&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Java SE enumerated types&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implicit objects&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaij"&gt;Implicit Objects&lt;/a&gt; for more detail on the implicit objects available with JSP technology.&lt;/p&gt;&lt;p&gt;To refer to these objects, you write an expression using a variable name
with which you created the object. The following expression references a JavaBeans component
called &lt;tt&gt;customer&lt;/tt&gt;.&lt;/p&gt;&lt;pre&gt;${customer}&lt;/pre&gt;&lt;p&gt;The web container evaluates a variable that appears in an expression by looking
up its value according to the behavior of &lt;tt&gt;PageContext.findAttribute(String)&lt;/tt&gt;, where the &lt;tt&gt;String&lt;/tt&gt;
argument is the name of the variable. For example, when evaluating the expression
&lt;tt&gt;${customer}&lt;/tt&gt;, the container will look for &lt;tt&gt;customer&lt;/tt&gt; in the page, request, session, and application
scopes and will return its value. If &lt;tt&gt;customer&lt;/tt&gt; is not found, null is
returned. A variable that matches one of the implicit objects described in &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaij"&gt;Implicit Objects&lt;/a&gt;
will return that implicit object instead of the variable’s value.&lt;/p&gt;&lt;p&gt;You can alter the way variables are resolved with a custom EL
resolver, which is a new feature of the unified EL. For instance, you
can provide an EL resolver that intercepts objects with the name &lt;tt&gt;customer&lt;/tt&gt;, so that
&lt;tt&gt;${customer}&lt;/tt&gt; returns a value in the EL resolver instead. However, you cannot override
implicit objects in this way. See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaih"&gt;EL Resolvers&lt;/a&gt; for more information on EL
resolvers.&lt;/p&gt;&lt;p&gt;You can set the variable name, &lt;tt&gt;customer&lt;/tt&gt;, when you declare the bean. See
&lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnair.html#bnait"&gt;Creating and Using a JavaBeans Component&lt;/a&gt; for information on how to declare a JavaBeans component for use in
your JSP pages.&lt;/p&gt;&lt;p&gt;To declare beans in JavaServer Faces applications, you use the managed bean facility.
See &lt;a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnaqm.html"&gt;Backing Beans&lt;/a&gt; for information on how to declare beans for use in JavaServer
Faces applications.&lt;/p&gt;&lt;p&gt;When referencing an enum constant with an expression, you use a &lt;tt&gt;String&lt;/tt&gt;
literal. For example, consider this Enum class:&lt;/p&gt;&lt;pre&gt;public enum Suit {hearts, spades, diamonds, clubs}&lt;/pre&gt;&lt;p&gt;To refer to the &lt;tt&gt;Suit&lt;/tt&gt; constant, &lt;tt&gt;Suit.hearts&lt;/tt&gt;