Java Reference
In-Depth Information
L ISTING 20.9
Continued
}
}
finally {
pool.releaseConnection(con);
}
}
}
The AddToCart Service
The AddToCart class is also an implementation of the Service.execute() method. Its
execute() method starts its execution when a user selects a movie from the ListMovies.jsp ,
which lists all of the movies found as a result of the ListMovies service. It gets the ID of the
selected movie from the request and performs a select statement on the Titles table, returning a
ResultSet containing the movie's attributes. It then adds these attributes to the ShoppingCart
found in the user's HttpSession and forwards the process to the named target on the request,
which in this case is the previously listed ListShoppingCart.jsp . The source for the
AddToCart service is in Listing 20.10.
L ISTING 20.10
AddToCart.java
import Service;
import ShoppingCart;
import ConnectionPool.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletContext;
import java.sql.*;
public class AddToCart implements Service {
public AddToCart() {
}
20
/*
implemented method from Service interface
*/
public void execute(HttpServletRequest request,
HttpServletResponse response,
ServletContext context) throws Exception {
 
Search WWH ::




Custom Search