Final Exam Review
Explain, with examples and UML diagrams, the mechanics and usefulness of:
servlet
servlet container
servlet lifecycle
context, session, request, and response
session management
forward and include
application, session, request, and page scope
the HTTP protocol
the role of the web.xml file
Java Bean
JSP to Servlet translationWhy is it a bad idea to use instance variables in a servlet?
How is a Java bean different from an ordinary object?
Patterns
Explain (with class diagrams, examples, and words) the following patterns and concepts:
Container-Component architecture
N-tier architectures
Model-View-Controller architecture
Service-to-Worker pattern
Dispatcher-View pattern
Data Access Objects
Value Objects
Entities
Front Controller Pattern
Views and View Helpers
JSP
Be able to write simple Java Server pages that incorporate the following features
scriptlets
actions: forawrd, include, param, useBean, setProperty, getProperty
implicit objects: application, session, request, response, out, pageWrite a JSP that presents first-time visitors with a form where they can enter their name. The visitor's name and IP address are stored. On subsequent visits, the visitor is simply presented with a customized greeting such as: "Hello, Joe Smith"
JDBC
Suppose the following single-table database is defined:
create table inventory (
upc int constraint pk_upc primary key,
name char(30) unique,
description varchar(60),
price numeric (8, 2),
)
insert into inventory values (1, 'Draino', 'drain cleaner', 2.89)
insert into inventory values (2, 'Jack Daniels', 'whiskey', 25.32)
etc.Write an inventory DAO that will give the price of an item from its name:
class InventoryDAO {
public double getPrice(String itemName) {
connection
= DriverManager.getConnection(dbaseName, username, password);
statement = connection.createStatement();
result = statement.execute(
"select price from inventory where name = " + itemName);
extract and return price from result
}
}
XML, JAXP
Be able to create XML, DTD, and simple XSL files
Be able to explain what a web server does when it gets a request for an XML documentRedo the JDBC problem, except the inventory is represented by a single XML file:
<?xml version="1.0"?>
<!DOCTYPE inventory SYSTEM "inventory.dtd">
<?xml-stylesheet type="text/xsl" href="inventory.xsl"?>
<inventory>
<product>
<upc> 1 </upc>
<name> Jack Daniels </name>
<description> whiskey </description>
<price> 25.42 </price>
</product>
<product>
<upc> 1 </upc>
<name> Alpo </name>
<description> dog food </description>
<price> 25.42 </price>
</product>
<product>
<upc> 1 </upc>
<name> Wando </name>
<description> magic wand </description>
<price> 25.42 </price>
</product>
</inventory>Write a DTD and simplee one-template style sheet for this file.
Draw an object diagram showing how this document will be parsed into a tree by DOM
The inventory DAO now uses DOM (or SAX) to locate prices:
class InventoryDAO {
public double getPrice(String itemName) {
Document doc = makeDocument("inventory1.xml");
NodeList prods = doc.getElementsByTagName("product");
for(int i = 0; i < prods.getLength(); i++) {
Element e = (Element)prods.item(i);
NodeList nodes = e.getElementsByTagName("name");
Node node = nodes.item(0).getFirstChild();
String s = node.getNodeValue().trim();
if (itemName.equals(s)) ???
}
}