Boolean orderCreated = false;
Timestamp orderDate = new Timestamp(new Date().getTime()); //record the current time
//retrieve the order object stored as a session attribute
//store the current time as the order date
Order order = (Order) request.getSession().getAttribute("order");
order.setOrderDate(orderDate);
//store the order in the MySQL database
try {
orderCreated = orderEjb.CreateOrder(dbUrl,
dbUsername,
dbPassword,
customerUsername,
order);
} catch (Exception ex) {
//allow exceptions to bubble up to the calling method, so they are displayed to the user
throw new ServletException(ex);
}
//display a completion message to the user if the database insertion was successfull
if (orderCreated) {
request.getSession().setAttribute("order", new Order());
RequestDispatcher view = request.getRequestDispatcher("/user/orderCompleted.jsp");
view.forward(request, response);
} else {
//display an error message if there was a problem adding the order to the database
request.setAttribute("error", "stockError");