Java Reference
In-Depth Information
Let's look at the details of the servlet:
B
The servlet's
init()
method creates
PlaceOrderService
and
RestaurantReposi-
tory
.
The servlet validates the parameters and creates the delivery address and delivery
time objects.
C
D
E
F
G
It gets the pending order
ID
from the
HttpSession
.
The servlet invokes
PlaceOrderService.updateDeliveryInfo()
.
The servlet stores the pending order
ID
in the
HttpSession
.
It selects the
JSP
page to use to generate the response based on the outcome of
calling the
PlaceOrder
. For example, if the call to
updateDeliveryInfo()
succeeds,
the servlet calls
displayAvailableRestaurants()
.
The
displayAvailableRestaurant()
method retrieves the list of available restau-
rants by calling
RestaurantRepository
.
The
displayAvailableRestaurant()
method forwards the request to the
JSP
page
availableRestaurants.jsp, passing
PendingOrder
and the list of restaurants as
HttpServletRequest
attributes.
The other servlets are similar. They validate the request parameters, invoke the
PlaceOrderService
, and forward the request to a
JSP
page.
H
I
8.4.2
JSP page design
The
JSP
pages generate
HTML
using the domain objects passed to them by the serv-
lets. Each
JSP
page navigates the object graph and displays the properties of domain
objects. Here is an excerpt of the
JSP
page that displays the available restaurants:
<%@ page import="net.chrisrichardson.foodToGo.domain.*,
bbbbbbbbbbb
b
➥
java.util.*" %>
<%
PendingOrder pendingOrder =
(PendingOrder)request.getAttribute("pendingOrder");
List restaurants = (List)request.getAttribute("restaurants");
%>
…
This excerpt shows how the
JSP
page gets the
PendingOrder
and the list of restau-
rants from the
HttpServletRequest
. It then uses them to generate the
HTML
response. The other
JSP
pages are similar.
Search WWH ::
Custom Search