Transcript advjhtp1_11

Chapter 11 Case Study: Servlet and JSP
Bookstore
Outline
11.1
11.2
11.3
11.4
11.5
11.6
11.7
11.8
11.9
Introduction
Bookstore Architecture
Entering the Bookstore
Obtaining the Book List from the Database
Viewing a Book’s Details
Adding an Item to the Shopping Cart
Viewing the Shopping Cart
Checking Out
Processing the Order
 2002 Prentice Hall. All rights reserved.
Chapter 11 Case Study: Servlet and JSP
Bookstore
11.10
Deploying the Bookstore Application in J2EE 1.2.1
11.10.1 Configuring the books Data Source
11.10.2 Launching the Cloudscape Database and J2EE
Servers
11.10.3 Launching the J2EE Application Deployment Tool
11.10.4 Creating the Bookstore Application
11.10.5 Creating BookServlet and AddToCartServlet
Web Components
11.10.6 Adding Non-Servlet Components to the Application
11.10.7 Specifying the Web Context, Resource References,
JNDI Names and Welcome Files
11.10.8 Deploying and Executing the Application
 2002 Prentice Hall. All rights reserved.
11.1 Introduction
• Bookstore Web application
–
–
–
–
JDBC
XML
JSP
Servlet
• J2EE application server
– http://java.sun.com/j2ee/download.html
 2002 Prentice Hall. All rights reserved.
11.2 Bookstore Architecture
• Three-tier distributed Web-based application
– Client tier
• Web browser
– Server tier
• JSPs and servlets
– Database tier
• books database
 2002 Prentice Hall. All rights reserved.
11.2 Bookstore Architecture (Cont.)
books.jsp
displayBook
addToCart
index.html
viewCart.jsp
XHTML d oc ument
process.jsp
JSP or serv le t
order.html
Fig. 11.1 Bug2Bug.com bookstore component interactions.
 2002 Prentice Hall. All rights reserved.
11.2 Bookstore Architecture (Cont.)
File
De sc rip tio n
index.html
This is the default home page for the bookstore, which is displayed by entering the
following URL in the client’s Web browser:
http://localhost:8000/advjhtp1/store
styles.css
This Cascading Style Sheet (CSS) file is linked to all XHTML documents rendered
on the client. The CSS file allows us to apply uniform formatting across all the
XHTML static and dynamic documents rendered.
books.jsp
This JSP uses
BookBean objects and a TitlesBean object to create an
TitlesBean object
queries the books database to obtain the list of titles in the database. The results
are processed and placed in an ArrayList of BookBean objects. The
XHTML document containing the product list. The
list is stored as a session attribute for the client.
BookBean.java
An instance of this JavaBean represents the data for one book. The bean’s
getXML method returns an XML Element representing the book.
TitlesBean.java
JSP
BookServlet.java
This servlet (aliased as displayBook in Fig. 11.1) obtains the XML
representation of a book selected by the user, then applies an XSL transformation
to the XML to produce an XHTML document that can be rendered by the client. In
this example, the client is assumed to be a browser that supports Cascading Style
Sheets (CSS). Later examples in this book apply different XSL transformations for
different client types.
books.jsp uses an instance of this JavaBean to obtain an
ArrayList containing a BookBean for every product in the database.
Fig. 11.2 (Part 1 of 2) Servlet and JSP components for bookstore case study.
 2002 Prentice Hall. All rights reserved.
11.2 Bookstore Architecture (Cont.)
book.xsl
This XSL style sheet specifies how to transform the XML
representation of a book into an XHTML document that
the client browser can render.
CartItemBean.java
An instance of this JavaBean maintains a BookBean and
the current quantity for that book in the shopping cart.
These beans are stored in a HashMap that represents the
contents of the shopping cart.
AddToCartServlet.java This servlet (aliased as addToCart in Fig. 11.1)
updates the shopping cart. If the cart does not exist, the
servlet creates a cart (a HashMap in this example). If a
CartItemBean for the item is already in the cart, the
servlet updates the quantity of that item in the bean.
Otherwise, the servlet creates a new CartItemBean
with a quantity of 1. After updating the cart, the user is
forwarded to viewCart.jsp to view the current cart
contents.
viewCart.jsp
This JSP extracts the CartItemBeans from the
shopping cart, subtotals each item in the cart, totals all the
items in the cart and creates an XHTML document that
allows the client to view the cart in tabular form.
order.html
When viewing the cart, the user can click a Check Out
button to view this order form. In this example, the form
has no functionality. However, it is provided to help
complete the application.
process.jsp
This final JSP pretends to process the user’s credit-card
information and creates an XHTML document indicating
that the order was processed and the total order value.
Fig. 11.2
(Pa rt 2 of 2) Se rvle t a nd JSP c o m p o ne nts fo r b o o ksto re c a se
stud y.
 2002 Prentice Hall. All rights reserved.
11.3 Entering the Bookstore
• Welcome file
– Default home page for the bookstore casestudy
 2002 Prentice Hall. All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- index.html -->
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Shopping Cart Case Study</title>
<link rel = "stylesheet" href = "styles.css"
type = "text/css" />
</head>
Outline
Fig. 11.3
Bookstore home
page
(index.html).
Specify a linked style
Lines 11-12
sheet styles.css.
Lines 24-27
<body>
<p class = "bigFont">Bug2Bug.com</p>
<p class = "bigFont italic">
Deitel & Associates, Inc.<br />
Shopping Cart Case Study
</p>
<!-- form to request books.jsp -->
<form method = "get" action = "books.jsp">
<p><input type = "submit" name = "enterButton"
value = "Click here to enter store" /></p>
</form>
</body>
The form provides a
submit button that enables
the users to enter the store.
</html>
 2002 Prentice Hall.
All rights reserved.
Outline
Fig. 11.3
Bookstore home
page
(index.html).
Program output
 2002 Prentice Hall.
All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
body
.bold
.bigFont
.italic
.right
table, th, td
table
Set the body
Outline
{ text-align: center;
element
background-color: #B0C4DE; }Defines
classformat.
.bold
{ font-weight: bold; }
to apply bold font
{ font-family: helvetica, arial, sans-serif;
Fig. 11.4 Shared
Define class .bigFont
font-weight: bold;
cascading style
font-size: 2em;
with four CSS attributes.
color: #00008B; }
sheet
{ font-style: italic; }
Define class .italic to apply italic font
(style.css) used
{ text-align: right; }
style and class .right to right justify text.
to apply common
{ border: 3px groove;
Set the th, td
padding: 5px; }
formatting
element format.
{ background-color: #6495ed;
across XHTML
Set the table
margin-left: auto;
documents
element format.
margin-right: auto }
rendered on the
client.
Lines 1-2
Line 3
Lines 4-7
Line 8, 9
Lines 10-11
Lines 12-14
 2002 Prentice Hall.
All rights reserved.
11.4 Obtaining the Book List from the
Database
• books.jsp
– Generates an XHTML document containing hyperlinks
• TitlesBean
– Performs a database query
• BookBean
– Stores query results
 2002 Prentice Hall. All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// TitlesBean.java
// Class TitlesBean makes a database connection and retrieves
// the books from the database.
package com.deitel.advjhtp1.store;
// Java core packages
import java.io.*;
import java.sql.*;
import java.util.*;
// Java extension packages
import javax.naming.*;
import javax.sql.*;
public class TitlesBean implements Serializable {
private Connection connection;
private PreparedStatement titlesQuery;
// construct TitlesBean object
Attempts the connection to the
public TitlesBean()
database using class InitialContext
{
DataSource.
// attempt database connection and
and interface
setup SQL
statements
try {
Creates a new
InitialContext ic = new InitialContext();
DataSource source =
( DataSource ) ic.lookup(
"java:comp/env/jdbc/books" );
connection = source.getConnection();
Outline
Fig. 11.5
TitlesBean for
obtaining book
information from
the books
database and
creating an
ArrayList of
BookBean
objects.
Lines 20-49
Line 24
InitialContext. Lines 26-28
Invoke InitialContext method lookup
to locate the books data Line
source. 30
Uses the DataSource to
connect to the database.
 2002 Prentice Hall.
All rights reserved.
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
titlesQuery =
connection.prepareStatement(
"SELECT isbn, title, editionNumber, " +
"copyright, publisherID, imageFile, price " +
"FROM titles ORDER BY title"
);
}
// process exceptions during database setup
catch ( SQLException sqlException ) {
sqlException.printStackTrace();
}
// process problems locating data source
catch ( NamingException namingException ) {
namingException.printStackTrace();
}
Outline
Fig. 11.5
TitlesBean for
obtaining book
information from
the books
database and
creating an
ArrayList of
BookBean
objects.
}
// return a List of BookBeans
public List getTitles()
{
List titlesList = new ArrayList();
// obtain list of titles
try {
ResultSet results = titlesQuery.executeQuery();
Line 58
Line 62
Lines 64-72
Execute titlesQuery.
// get row data
while ( results.next() ) {
BookBean book = new BookBean();
Creates a new BookBean.
Set the attributes of the
book.setISBN( results.getString( "isbn" ) );
BookBean to columns
book.setTitle( results.getString( "title" ) );
 2002 Prentice
in the ResultSet
row.Hall.
All rights reserved.
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
book.setEditionNumber(
results.getInt( "editionNumber" ) );
book.setCopyright( results.getString( "copyright" ) );
book.setPublisherID(
results.getInt( "publisherID" ) );
book.setImageFile( results.getString( "imageFile" ) );
book.setPrice( results.getDouble( "price" ) );
titlesList.add( book );
}
Adds the new BookBean
to ArrayList titlesList.
}
// process exceptions during database query
catch ( SQLException exception ) {
exception.printStackTrace();
}
// return the list of titles
finally {
return titlesList;
}
Outline
Fig. 11.5
TitlesBean for
obtaining book
information from
the books
database and
creating an
ArrayList of
BookBean
objects.
Line 74
}
// close statements and terminate database connection
protected void finalize()
{
// attempt to close database connection
try {
connection.close();
}
 2002 Prentice Hall.
All rights reserved.
97
98
99
100
101
102
// process SQLException on close operation
catch ( SQLException sqlException ) {
sqlException.printStackTrace();
}
}
}
Outline
Fig. 11.5
TitlesBean for
obtaining book
information from
the books
database and
creating an
ArrayList of
BookBean
objects.
 2002 Prentice Hall.
All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// BookBean.java
// A BookBean object contains the data for one book.
package com.deitel.advjhtp1.store;
// Java core packages
import java.io.*;
import java.text.*;
import java.util.*;
// third-party packages
import org.w3c.dom.*;
public class BookBean implements Serializable {
private String ISBN, title, copyright, imageFile;
private int editionNumber, publisherID;
private double price;
Outline
Fig. 11.6
BookBean that
represents a
single book’s
information and
defines the XML
format of that
information.
// set ISBN number
public void setISBN( String isbn )
{
ISBN = isbn;
}
// return ISBN number
public String getISBN()
{
return ISBN;
}
// set book title
public void setTitle( String bookTitle )
{
title = bookTitle;
}
 2002 Prentice Hall.
All rights reserved.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// return book title
public String getTitle()
{
return title;
}
// set copyright year
public void setCopyright( String year )
{
copyright = year;
}
// return copyright year
public String getCopyright()
{
return copyright;
}
Outline
Fig. 11.6
BookBean that
represents a
single book’s
information and
defines the XML
format of that
information.
// set file name of image representing product cover
public void setImageFile( String fileName )
{
imageFile = fileName;
}
// return file name of image representing product cover
public String getImageFile()
{
return imageFile;
}
// set edition number
public void setEditionNumber( int edition )
{
editionNumber = edition;
}
 2002 Prentice Hall.
All rights reserved.
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// return edition number
public int getEditionNumber()
{
return editionNumber;
}
// set publisher ID number
public void setPublisherID( int id )
{
publisherID = id;
}
// return publisher ID number
public int getPublisherID()
{
return publisherID;
}
Outline
Fig. 11.6
BookBean that
represents a
single book’s
information and
defines the XML
format of that
information.
// set price
public void setPrice( double amount )
{
price = amount;
}
// return price
public double getPrice()
{
return price;
}
 2002 Prentice Hall.
All rights reserved.
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// get an XML representation of the Product
public Element getXML( Document document )
{
// create product root element
Element product = document.createElement( "product" );
Outline
Fig. 11.6
BookBean that
// create isbn element, append as child of product
Uses Document
method a
represents
Element temp = document.createElement( "isbn" );
Uses
Document
createElement
to create
single
book’s
temp.appendChild( document.createTextNode(
getISBN()
); as a child
Appends
element) isbn
method
element isbn.
information and
product.appendChild( temp );
of element product with Element
createTextNode
defines the toXML
method
appendChild.
// create title element, append as child
of product
specify
theof
textthat
in
format
temp = document.createElement( "title" );
the
isbn element.
information.
temp.appendChild( document.createTextNode( getTitle() ) );
product.appendChild( temp );
Line 109
// create a currency formatting object for US dollars
Obtain
a
NumberFormat
NumberFormat priceFormatter =
NumberFormat.getCurrencyInstance( Locale.US ); object that formats
Linecurrency
110
for the U.S. local to format
book price Line
in US dollars.
111
// create price element, append as child of product
the
temp = document.createElement( "price" );
temp.appendChild( document.createTextNode(
priceFormatter.format( getPrice() ) ) );
product.appendChild( temp );
Lines 119-120
// create imageFile element, append as child of product
temp = document.createElement( "imageFile" );
temp.appendChild(
document.createTextNode( getImageFile() ) );
product.appendChild( temp );
 2002 Prentice Hall.
All rights reserved.
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// create copyright element, append as child of product
temp = document.createElement( "copyright" );
temp.appendChild(
document.createTextNode( getCopyright() ) );
product.appendChild( temp );
// create publisherID element, append as child of product
temp = document.createElement( "publisherID" );
temp.appendChild( document.createTextNode(
String.valueOf( getPublisherID() ) ) );
product.appendChild( temp );
// create editionNumber element, append as child of product
temp = document.createElement( "editionNumber" );
temp.appendChild( document.createTextNode(
String.valueOf( getEditionNumber() ) ) );
product.appendChild( temp );
Outline
Fig. 11.6
BookBean that
represents a
single book’s
information and
defines the XML
format of that
information.
// return product element
return product;
}
}
 2002 Prentice Hall.
All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- books.jsp -->
<%-- JSP page settings --%>
<%@
page language = "java"
import = "com.deitel.advjhtp1.store.*, java.util.*"
session = "true"
%>
<!-- begin document -->
<html xmlns = "http://www.w3.org/1999/xhtml">
Outline
Fig. 11.7 JSP
books.jsp
returns to the
Specify the client
JSP
an XHTML
page settings.
document
containing the
book list.
<head>
<title>Book List</title>
<link rel = "stylesheet" href = "styles.css"
type = "text/css" />
</head>
Lines 7-11
Line 32
Line 33
<body>
<p class = "bigFont">Available Books</p>
<p class = "bold">Click a link to view book information</p>
<p>
<%-- begin JSP scriptlet to create list of books --%>
<%
TitlesBean titlesBean = new TitlesBean();
Invokes
Creates TitlesBean’s
a TitlesBean.getTitles method
List titles = titlesBean.getTitles();
to obtain the List of BookBean objects.
BookBean currentBook;
 2002 Prentice Hall.
All rights reserved.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Outline
Sets a titles session attribute
to store the List for user
// obtain an Iterator to the set of keys in the
List
later
the client’s session.
Obtains
an in
Iterator
Fig. 11.7 JSP
Iterator iterator = titles.iterator();
for the List.
books.jsp
// use the Iterator to get each BookBean and create
returns to the
// a link to each book
client an XHTML
while ( iterator.hasNext() ) {
document
currentBook = ( BookBean ) iterator.next();
Uses a JSP expression to insert the
containing the
book’s ISBN number as the value in a
<%-- end scriptlet to insert literal XHTML and --%>
book list.
<%-- JSP expressions output from this loop
--%>
name/value pair that is passed to the
displayBook servlet as an argument.
<%-- link to a book's information --%>
Line 37
// store titles in session for further use
session.setAttribute( "titles", titles );
%>
<span class = "bold">
<a href =
"displayBook?isbn=<%= currentBook.getISBN() %>">
<%= currentBook.getTitle() + ", " +
currentBook.getEditionNumber() + "e" %>
</a>
</span><br />
Line 40
Use another JSP expression
53 title and
to insertLine
the book’s
edition number as the text
Lines
displayed
for the55-56
hyperlink.
<% // continue scriptlet
}
// end while loop
%> <%-- end scriptlet --%>
</p>
</body>
</html>
 2002 Prentice Hall.
All rights reserved.
Outline
Fig. 11.7 JSP
books.jsp
returns to the
client an XHTML
document
containing the
book list.
Program output
 2002 Prentice Hall.
All rights reserved.
11.5 Viewing a Book’s Details
• BookServlet
– Transforms XML into and XHTML document
• Book.xsl
– XSL style sheet used in transformation
 2002 Prentice Hall. All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// BookServlet.java
// Servlet to return one book's information to the client.
// The servlet produces XML which is transformed with XSL to
// produce the client XHTML page.
package com.deitel.advjhtp1.store;
// Java core packages
import java.io.*;
import java.util.*;
// Java extension packages
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
// third-party packages
import org.w3c.dom.*;
import org.xml.sax.*;
public class BookServlet extends HttpServlet {
protected void doGet( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
HttpSession session = request.getSession( false );
Outline
Fig. 11.8
BookServlet
obtains the XML
representation
of a book and
applies an XSL
transformation
to output an
XHTML document
as the response
to the client.
Line 28
Lines 32-33
Obtains the HttpSession
object for the current client.
// RequestDispatcher to forward client to bookstore home
// page if no session exists or no books are selected
Obtain a RequestDispatcher
RequestDispatcher dispatcher =
request.getRequestDispatcher( "/index.html" ); the “/index.html”document.
for
 2002 Prentice Hall.
All rights reserved.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// if session does not exist, forward to index.html
if ( session == null )
dispatcher.forward( request, response );
Outline
Fig. 11.8
Get the List of BookBeans
BookServlet
from the session object.
obtains the XML
representation
// locate BookBean object for selected book
of a book and
Iterator iterator = titles.iterator();
BookBean book = null;
applies an XSL
transformation
String isbn = request.getParameter( "isbn" );
output
Perform a linear search to
to locate
the an
while ( iterator.hasNext() ) {
XHTML
BookBean for the selected
book.document
book = ( BookBean ) iterator.next();
as the response
to the client.
if ( isbn.equals( book.getISBN() ) ) {
// get books from session object
List titles =
( List ) session.getAttribute( "titles" );
// save the book in a session attribute
session.setAttribute( "bookToAdd", book );
break; // isbn matches current book
}
}
// if book is not in list, forward to index.html
if ( book == null )
dispatcher.forward( request, response );
Lines 40-41
Lines 44-58
Lines 68-69
// get XML document and transform for browser client
try {
// get a DocumentBuilderFactory for creating
// a DocumentBuilder (i.e., an XML parser)
Obtain a DocumentBuilderFactory
DocumentBuilderFactory factory =
for creating an XML
parser.
 2002
Prentice Hall.
DocumentBuilderFactory.newInstance();
All rights reserved.
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
Outline
// get a DocumentBuilder for building the
DOM atree
Obtain
DocumentBuilder parser object that
DocumentBuilder builder =
enables the program to create a Document
factory.newDocumentBuilder();
Fig.document
11.8
object tree in which the XML
BookServlet
// create a new Document (empty DOM tree)
elements are represented
as Element objects.
Uses the
Document messageDocument = builder.newDocument();
obtains the
XML
DocumentBuilder
object
representation
// get XML from BookBean and append to Document
to create
a new
Invokes
theDocument.
of a book and
Element bookElement = book.getXML( messageDocument );
BookBean’s
getXML
messageDocument.appendChild( bookElement );
applies an XSL
method to obtain an
transformation
// get PrintWriter for writing data to client
Element representation
Specify the response
contentan
type
to output
response.setContentType( "text/html" );
of
the
book.
PrintWriter out = response.getWriter();
and obtain a PrintWriter
to
XHTML document
output the response
to the
client.
as the
response
// open InputStream for XSL document
Create an InputStream
will
to thethatclient.
InputStream xslStream =
be used by the XSL transformation
getServletContext().getResourceAsStream(
"/book.xsl" );
processor to readLines
the XSL72-73
file.
// transform XML document using XSLT
transform( messageDocument, xslStream, out );
// flush and close PrintWriter
out.flush();
out.close();
}
// catch XML parser exceptions
catch ( ParserConfigurationException pcException ) {
pcException.printStackTrace();
}
}
Line 76
Line 79
Lines 83-84
Lines 87-89
 2002 Prentice Hall.
All rights reserved.
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// transform XML document using provided XSLT InputStream
// and write resulting document to provided PrintWriter
private void transform( Document document,
InputStream xslStream, PrintWriter output )
{
try {
// create DOMSource for source XML document
Source xmlSource = new DOMSource( document );
Outline
Fig. 11.8
BookServlet
Creates a obtains
DOMSource
the XML
that represents
the
representation
XML document.
of a book and
// create StreamSource for XSLT document
Create
a
StreamSource
Source xslSource =
applies an XSL
new StreamSource( xslStream );for the XSL file.
transformation
to output for
an
// create StreamResult for transformation result
Creates a StreamResult
Result result = new StreamResult( output );
XHTML to
document
the PrinterWriter
which
asthethe
XSLresponse
// create TransformerFactory to obtain a Transformerthe results of
to are
thewritten.
client.
TransformerFactory transformerFactory =
transformation
TransformerFactory.newInstance();
Line 112
// create Transformer for performing XSL transformation
Create a Transformer using
Transformer transformer =
transformerFactory.newTransformer( xslSource ); TransformerFactory
Lines 115-116
// perform transformation and deliver content to
transformer.transform( xmlSource, result );
}
// handle exception when transforming XML document
catch ( TransformerException transformerException )
transformerException.printStackTrace( System.err
}
}
}
method newTransformer.
client
Invokes Transformer
Line 119 method
transform to perform the XSL
transformation
the given
Lineson 126-127
DOMSource object and writes
{
to the given
); the resultLine
130
StreamResult object.
 2002 Prentice Hall.
All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Outline
<?xml version = "1.0"?>
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
version = "1.0">
<xsl:output method = "xml" omit-xml-declaration = "no"
indent = "yes" doctype-system =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN"/>
<!-- book.xsl
-->
<!-- XSL document that transforms XML into XHTML -->
<!-- specify the root of the XML document -->
<!-- that references this stylesheet
-->
<xsl:template match = "product">
Fig. 11.9 XSL
style sheet
(books.xsl) that
transforms a
book’s XML
representation
into an XHTML
document.
Lines 23 and 30
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<!-- obtain book title from JSP to place in title -->
<title><xsl:value-of select = "title"/></title>
<link rel = "stylesheet" href = "styles.css"
type = "text/css" />
</head>
Place the book’s title in the
document’s title element and
in a paragraph at the
beginning of the document’s
body element, respectively.
<body>
<p class = "bigFont"><xsl:value-of select = "title"/></p>
<table>
<tr>
 2002 Prentice Hall.
All rights reserved.
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!-- create table cell for product image -->
<td rowspan = "5"> <!-- cell spans 5 rows -->
<img border = "thin solid black" src =
"images/{ imageFile }" alt = "{ title }" />
</td>
<!-- create table cells for price in row 1 -->
<td class = "bold">Price:</td>
<td><xsl:value-of select = "price"/></td>
</tr>
<tr>
<!-- create table cells for ISBN in row 2 -->
<td class = "bold">ISBN #:</td>
<td><xsl:value-of select = "isbn"/></td>
</tr>
<tr>
Outline
Specifies an img element in
which the value of the
Fig. 11.9 XSL
imageFile element of an
style sheet
XML document specifies the
(books.xsl) that
name of the file representing
transforms a
the book’s cover image.
book’s XML
representation
into an XHTML
document.
Line 36
43,
51, 59
PlaceLines
the book’s
price,
67
isbn, and
editionNumber
and
copyright in table cells.
<!-- create table cells for edition in row 3 -->
<td class = "bold">Edition:</td>
<td><xsl:value-of select = "editionNumber"/></td>
</tr>
<tr>
<!-- create table cells for copyright in row 4 -->
<td class = "bold">Copyright:</td>
<td><xsl:value-of select = "copyright"/></td>
</tr>
 2002 Prentice Hall.
All rights reserved.
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<tr>
<!-- create Add to Cart button in row 5 -->
<td>
<form method = "post" action = "addToCart">
<input type = "submit" value = "Add to Cart" />
</form>
</td>
<!-- create View Cart button in row 5 -->
<td>
<form method = "get" action = "viewCart.jsp">
<input type = "submit" value = "View Cart" />
</form>
</td>
</tr>
</table>
Outline
Fig. 11.9 XSL
style sheet
(books.xsl) that
transforms a
book’s XML
representation
into an XHTML
document.
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 2002 Prentice Hall.
All rights reserved.
Outline
Fig. 11.9 XSL
style sheet
(books.xsl) that
transforms a
book’s XML
representation
into an XHTML
document.
Program output
 2002 Prentice Hall.
All rights reserved.
11.6 Adding an Item to the Shopping Cart
• AddToCartServlet
– Updates the shopping cart
• CartItemBean
– Represents items in the shopping cart
 2002 Prentice Hall. All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// CartItemBean.java
// Class that maintains a book and its quantity.
package com.deitel.advjhtp1.store;
import java.io.*;
public class CartItemBean implements Serializable {
private BookBean book;
private int quantity;
// initialize a CartItemBean
public CartItemBean( BookBean bookToAdd, int number )
{
book = bookToAdd;
quantity = number;
}
Outline
Fig. 11.10
CartItemBeans
contain a
BookBean and the
quantity of a
book in the
shopping cart.
// get the book (this is a read-only property)
public BookBean getBook()
{
return book;
}
// set the quantity
public void setQuantity( int number )
{
quantity = number;
}
// get the quantity
public int getQuantity()
{
return quantity;
}
}
 2002 Prentice Hall.
All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// AddToCartServlet.java
// Servlet to add a book to the shopping cart.
package com.deitel.advjhtp1.store;
// Java core packages
import java.io.*;
import java.util.*;
// Java extension packages
import javax.servlet.*;
import javax.servlet.http.*;
public class AddToCartServlet extends HttpServlet {
protected void doPost( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
HttpSession session = request.getSession( false );
RequestDispatcher dispatcher;
Outline
Fig. 11.11
AddToCartServlet
places an item
in the shopping
cart and invokes
viewCart.jsp to
display the cart
contents.
Line 18
Obtains the HttpSession
object for the current client.
Lines 22-26
// if session does not exist, forward Forwards
to index.html
the request to the bookstore home
Line 29
if ( session == null ) {
page
index.html
if
a
session
does
not exist.
dispatcher =
request.getRequestDispatcher( "/index.html" );
Lines 30-31
dispatcher.forward( request, response );
}
// session exists, get cart Map and book to add
Map cart = ( Map ) session.getAttribute( "cart" );
BookBean book =
( BookBean ) session.getAttribute( "bookToAdd" );
Lines 34-39
Obtains the value of
session
cart.
Obtain
the attribute
value of session
attribute bookToAdd.
// if cart does not exist, create
it a new HashMap to store the cart contents and place
Create
if ( cart == null ) {
the HashMap in the cart attribute of the
object.
 session
2002 Prentice
Hall.
cart = new HashMap();
All rights reserved.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Outline
// update the cart attribute
session.setAttribute( "cart", cart );
}
Fig. 11.11
AddToCartServlet
// determine if book is in cart
Locate
the
CartItemBean
for item
CartItemBean cartItem =
places an
( CartItemBean ) cart.get( book.getISBN() );
the book being added
to theshopping
cart.
in the
cart and invokes
// If book is already in cart, update its quantity.
// Otherwise, create an entry in the cart.
viewCart.jsp to
if ( cartItem != null )
Increments
thethe
quantity
display
cart
cartItem.setQuantity( cartItem.getQuantity() + 1 );
forcontents.
the CartItemBean.
else
Creates a new
cart.put( book.getISBN(), new CartItemBean( book, 1 ) );
// send the user to viewCart.jsp
dispatcher =
request.getRequestDispatcher( "/viewCart.jsp" );
dispatcher.forward( request, response );
}
}
CartItemBean
Lines
42-43 of
with a quantity
Create a RequestDispatcher for JSP
1 and put it into
viewCart.jsp Line
and forward
48 the
the shopping
cart.
processing of the request to that JSP.
Line 50
Lines 53-55
 2002 Prentice Hall.
All rights reserved.
11.7 Viewing the Shopping Cart
• JSP viewCart.jsp
– Extracts the CartItemBeans from the shopping cart
– Subtotals each item in the cart
– Totals all the items in the cart
– Creates an XHTML document to view the cart
 2002 Prentice Hall. All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Outline
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- viewCart.jsp -->
<%-- JSP
<%@ page
<%@ page
<%@ page
<%@ page
Fig. 11.12 JSP
viewCart.jsp
obtains the
shopping cart
and outputs an
XHTML document
with the cart
contents in
tabular format.
page settings --%>
language = "java" session = "true" %>
import = "com.deitel.advjhtp1.store.*" %>
import = "java.util.*" %>
import = "java.text.*" %>
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Shopping Cart</title>
<link rel = "stylesheet" href = "styles.css"
type = "text/css" />
</head>
Line 26
<body>
<p class = "bigFont">Shopping Cart</p>
<%-- start scriptlet to display shopping cart contents --%>
<%
Map cart = ( Map ) session.getAttribute( "cart" );
double total = 0;
Retrieves the session attribute
for the shopping cart.
if ( cart == null || cart.size() == 0 )
out.println( "<p>Shopping cart is currently empty.</p>" );
else {
// create variables used in display of cart
Set cartItems = cart.keySet();
Iterator iterator = cartItems.iterator();
 2002 Prentice Hall.
All rights reserved.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Outline
BookBean book;
CartItemBean cartItem;
int quantity;
double price, subtotal;
%> <%-- end scriptlet for literal XHTML output --%>
<table>
<thead><tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr></thead>
Output the literal XHTML
markup that begins the table
that appears in the document.
Fig. 11.12 JSP
viewCart.jsp
obtains the
shopping cart
and outputs an
XHTML document
with the cart
contents in
tabular format.
Lines 45-51
The while loop uses each key in the Map to
while ( iterator.hasNext() ) {
55-63
obtain the correspondingLines
CartItemBean,
// get book data; calculate subtotal and extracts
total the data from that bean, calculates
cartItem = ( CartItemBean ) cart.get( iterator.next()
); for that product and
the dollar subtotal
book = cartItem.getBook();
calculates the dollar total for all products.
quantity = cartItem.getQuantity();
<% // continue scriptlet
price = book.getPrice();
subtotal = quantity * price;
total += subtotal;
%> <%-- end scriptlet for literal XHTML and
--%>
<%-- JSP expressions output from this loop --%>
 2002 Prentice Hall.
All rights reserved.
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<%-- display table row of book title, quantity, --%>
<%-- price and subtotal --%>
The preceding data is formatted
<tr>
into a row in the XHTML table.
<td><%= book.getTitle() %></td>
<td><%= quantity %></td>
<td class = "right">
<%=
new DecimalFormat( "0.00" ).format( price )
%>
</td>
<td class = "bold right">
<%=
new DecimalFormat( "0.00" ).format( subtotal )
%>
</td>
</tr>
Fig. 11.12 JSP
viewCart.jsp
obtains the
shopping cart
and outputs an
XHTML document
with the cart
contents in
tabular format.
Lines 70-86
Lines 95-100
<% // continue scriptlet
}
Outline
// end of while loop
%> <%-- end scriptlet for literal XHTML and
--%>
<%-- display table row containing shopping cart total
--%>the dollar total
Output
<tr>
of all items in the cart.
<td colspan = "4" class = "bold right">Total:
<%= new DecimalFormat( "0.00" ).format( total ) %>
</td>
</tr>
</table>
 2002 Prentice Hall.
All rights reserved.
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<% // continue scriptlet
}
// make current total a session attribute
session.setAttribute( "total", new Double( total ) );
// end of else
%> <%-- end scriptlet --%>
<!-- link back to books.jsp to continue shopping -->
<p class = "bold green">
<a href = "books.jsp">Continue Shopping</a>
</p>
<!-- form to proceed to checkout -->
<form method = "get" action = "order.html">
<p><input type = "submit" value = "Check Out" /></p>
</form>
</body>
Outline
Sets a session attribute
Fig. the
11.12
containing
total. JSP
viewCart.jsp
obtains the
shopping cart
and outputs an
XHTML document
with the cart
contents in
tabular format.
Line 105
</html>
 2002 Prentice Hall.
All rights reserved.
Outline
Fig. 11.12 JSP
viewCart.jsp
obtains the
shopping cart
and outputs an
XHTML document
with the cart
contents in
tabular format.
Program output
 2002 Prentice Hall.
All rights reserved.
11.8 Checking Out
• order.html
– Order form
 2002 Prentice Hall. All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- order.html -->
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Order</title>
<link rel = "stylesheet" href = "styles.css"
type = "text/css" />
</head>
<body>
<p class = "bigFont">Shopping Cart Check Out</p>
Outline
Fig. 11.13 Order
form
(order.html) in
which the user
inputs name,
address and
credit-card
information to
complete an
order.
<!-- Form to input user information and credit card.
-->
<!-- Note: No need to input real data in this example. -->
<form method = "post" action = "process.jsp">
<p style = "font-weight: bold">
Please input the following information.</p>
<!-- table of form elements -->
<table>
<tr>
<td class = "right bold">First name:</td>
<td>
<input type = "text" name = "firstname"
size = "25" />
</td>
</tr>
 2002 Prentice Hall.
All rights reserved.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<tr>
<td class = "right bold">Last name:</td>
<td>
<input type = "text" name = "lastname"
size = "25" />
</td>
</tr>
<tr>
<td class = "right bold">Street:</td>
<td>
<input type = "text" name = "street" size = "25" />
</td>
</tr>
Outline
Fig. 11.13 Order
form
(order.html) in
which the user
inputs name,
address and
credit-card
information to
complete an
order.
<tr>
<td class = "right bold">City:</td>
<td>
<input type = "text" name = "city" size = "25" />
</td>
</tr>
<tr>
<td class = "right bold">State:</td>
<td>
<input type = "text" name = "state" size = "2" />
</td>
</tr>
 2002 Prentice Hall.
All rights reserved.
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<tr>
<td class = "right bold">Zip code:</td>
<td>
<input type = "text" name = "zipcode"
size = "10" />
</td>
</tr>
<tr>
<td class = "right bold">Phone #:</td>
<td>
(
<input type = "text" name = "phone" size = "3" />
)
Outline
Fig. 11.13 Order
form
(order.html) in
which the user
inputs name,
address and
credit-card
information to
complete an
order.
<input type = "text" name = "phone2"
size = "3" /> <input type = "text" name = "phone3" size = "4" />
</td>
</tr>
<tr>
<td class = "right bold">Credit Card #:</td>
<td>
<input type = "text" name = "creditcard"
size = "25" />
</td>
</tr>
<tr>
<td class = "right bold">Expiration (mm/yy):</td>
 2002 Prentice Hall.
All rights reserved.
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<td>
<input type = "text" name = "expires"
size = "2" /> /
<input type = "text" name = "expires2"
size = "2" />
</td>
</tr>
</table>
<!-- enable user to submit the form -->
<p><input type = "submit" value = "Submit" /></p>
</form>
</body>
</html>
Outline
Fig. 11.13 Order
form
(order.html) in
which the user
inputs name,
address and
credit-card
information to
complete an
order.
 2002 Prentice Hall.
All rights reserved.
Outline
Fig. 11.13 Order
form
(order.html) in
which the user
inputs name,
address and
credit-card
information to
complete an
order.
 2002 Prentice Hall.
All rights reserved.
11.9 Processing the Order
• process.jsp
– Finalize the order
– Process the user’s credit-card information
– Creates order message
 2002 Prentice Hall. All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Outline
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- process.jsp -->
<html xmlns = "http://www.w3.org/1999/xhtml">
Fig. 11.14 JSP
process.jsp
performs the
final order
processing.
<head>
<title>Thank You!</title>
Line 22
<link rel = "stylesheet" href = "styles.css"
type = "text/css" />
</head>
Line 26
<%-- JSP page settings --%>
<%@ page language = "java" session = "true" %>
<%@ page import = "java.text.*" %>
<% // start scriptlet
// get total order amount
Double d = ( Double ) session.getAttribute( "total" );
double total = d.doubleValue();
Obtains the session
attribute total.
// invalidate session because processing is complete
Invokes HttpSession method
session.invalidate();
%> <%-- end scriptlet --%>
invalidate to discard the session
object for the current client.
<body>
<p class = "bigFont">Thank You</p>
<p>Your order has been processed.</p>
 2002 Prentice Hall.
All rights reserved.
35
36
37
38
39
40
41
42
<p>Your credit card has been billed:
<span class = "bold">
$<%= new DecimalFormat( "0.00" ).format( total ) %>
</span>
</p>
</body>
</html>
Outline
Uses a JSP expression to
insert the dollar total of
11.14 JSP
all Fig.
items purchased.
process.jsp
performs the
final order
processing.
Line 37
Program output
 2002 Prentice Hall.
All rights reserved.
11.10 Deploying the Bookstore Application
in J2EE 1.2.1
• Download and install J2EE 1.2.1
• Deploy Bookstore case study
– Configure the books data source
– Launch the Cloudscape database server and J2EE server
– Launch the Application Deployment Tool
–
–
–
–
–
–
–
Create a new application
Add library JAR files
Create a new Web component for the BookServlet
Create a new Web component for the AddToCartServlet
Add nonservlet components
Specify the Web context
Specify the database resource
 2002 Prentice Hall. All rights reserved.
11.10 Deploying the Bookstore Application
in J2EE 1.2.1 (Cont.)
–
–
–
–
Set up the JNDI name for the database
Set up the welcome file
Deploy the application
Run the application
 2002 Prentice Hall. All rights reserved.
11.10.1 Configure the books Data Source
• Configure the Cloudscape data source
– Modify default.properties
• |jdbc/books|jdbc:cloudscape:rmi:books;create=true
JNDI name for
the database
 2002 Prentice Hall. All rights reserved.
JDBC URL
Create a database if
the database does
not already exist
11.10.2 Launching the Cloudscape Database
and J2EE Servers
• Launch the Cloudscape server
– cloudscape -start
• Start the J2EE server
– j2ee -verbose
• Stop the J2EE server
– j2ee -stop
 2002 Prentice Hall. All rights reserved.
11.10.3 Launching the J2EE Application
Deployment Tool
• Application Deployment Tool
– Writes the deployment descriptor files
– Places all components into an EAR file
• Launch Application Deployment Tool
– deploytool
 2002 Prentice Hall. All rights reserved.
11.10.3 Launching the J2EE Application
Deployment Tool (Cont.)
New Application
New Web Component
Save
Application names
and application
component names
appear here
Fig. 11.15 Application Deployment Tool main window.
 2002 Prentice Hall. All rights reserved.
11.10.4 Creating the Bookstore Application
• Click New Application button
• Fill in fields in the New Application window
Fig. 11.16 New Application window.
 2002 Prentice Hall. All rights reserved.
11.10.4 Creating the Bookstore Application
(Cont.)
Fig. 11.17 Application Deployment Tool main window after creating a new application.
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
• New Web Component Wizard
– Create BookServlet Web component
– Create AddToCartServlet Web Component
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.18 New Web Component Wizard - Introduction window
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.19 New Web Component Wizard - WAR File General Properties window.
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.20 Add Files to .WAR - Add Content Files window.
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.21 Add Files to .WAR - Add Class Files window.
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.22 Choose Root Directory window.
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.23 Add Files to .WAR - Add Class Files window after selecting
the root directory in which the files are located.
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.24 New Web Component Wizard - WAR File General
Properties window after selecting the file BookServlet.class
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.25 New Web Component Wizard - Choose Component Type window.
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.26 New Web Component Wizard - Component General Properties window.
 2002 Prentice Hall. All rights reserved.
11.10.5 Creating BookServlet and
AddToCartServlet Web Components
(Cont.)
Fig. 11.27 New Web Component Wizard - Component Aliases window.
 2002 Prentice Hall. All rights reserved.
11.10.6 Adding Non-Servlet Components to
the Application
• Add non-servlet components
–
–
–
–
–
JSPs
XHTML documents
Style sheets
Images
JavaBeans
 2002 Prentice Hall. All rights reserved.
11.10.6 Adding Non-Servlet Components to
the Application (Cont.)
Fig. 11.28 Application Deployment Tool window
after deploying BookServlet and AddToCartServlet.
 2002 Prentice Hall. All rights reserved.
11.10.6 Adding Non-Servlet Components to
the Application (Cont.)
Fig. 11.29 Add Files to .WAR - Add Content Files window.
 2002 Prentice Hall. All rights reserved.
11.10.6 Adding Non-Servlet Components to
the Application (Cont.)
Fig. 11.30 Add Files to .WAR - Add Class Files window
 2002 Prentice Hall. All rights reserved.
11.10.7 Specifying the Web Context,
Resource References, JNDI Names and
Welcome Files
• Web Context
– advjhtp1/store
• Resource References
– jdbc/books
• JNDI Names
– jdbc/books
• Welcome Files
– index.html
 2002 Prentice Hall. All rights reserved.
11.10.7 Specifying the Web Context,
Resource References, JNDI Names and
Welcome Files (Cont.)
Fig. 11.31 Specifying the Web Context in the Application Deployment Tool.
 2002 Prentice Hall. All rights reserved.
11.10.7 Specifying the Web Context,
Resource References, JNDI Names and
Welcome Files (Cont.)
Fig. 11.32 Specifying the Resource Ref’s in the Application Deployment Tool.
 2002 Prentice Hall. All rights reserved.
11.10.7 Specifying the Web Context,
Resource References, JNDI Names and
Welcome Files (Cont.)
Fig. 11.33 Specifying the Resource Ref’s in the Application Deployment Tool.
 2002 Prentice Hall. All rights reserved.
11.10.7 Specifying the Web Context,
Resource References, JNDI Names and
Welcome Files (Cont.)
Fig. 11.34 Specifying the welcome file in the
File Ref’s tab of the Application Deployment Tool.
 2002 Prentice Hall. All rights reserved.
11.10.8 Deploying and Executing the
Application
• Update Application Files
• Deploy Appliction…
• Update and RedeployApplication
 2002 Prentice Hall. All rights reserved.
11.10.8 Deploying and Executing the
Application (Cont.)
Deploy Application…
Update Application Files
Update and
Redeploy
Application
Fig. 11.35 Application Deployment Tool toolbar buttons
for updating application files and deploying applications.
 2002 Prentice Hall. All rights reserved.
11.10.8 Deploying and Executing the
Application (Cont.)
Fig. 11.36 Deploy JSP and Servlet Bookstore - Introduction window.
 2002 Prentice Hall. All rights reserved.