Java Reference
In-Depth Information
The Sell Service
The Sell class is also an implementation of the Service interface. Its execute() method starts
its execution when a user selects the Sell radio button and fills in symbol and price information
from the tradeform.jsp page. It then gets the symbol and price from the request and performs
a select statement on the stocks table, returning a ResultSet containing the stock's attributes.
It then checks for an existing bid price that is either greater than or equal to the submitted Ask
price. If there is a satisfying bid price, the current price is set to the submitted ask price and the
bid price is reset to 0. Otherwise the new ask is updated. The source for the Sell service is
found in Listing 22.9.
L ISTING 22.9
Sell.java
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletContext;
import Service;
import java.sql.*;
import ConnectionPool.ConnectionPool;
public class Sell implements Service {
public Sell() {
}
/*
implemented method from Service interface
*/
public void execute(HttpServletRequest request,
HttpServletResponse response,
ServletContext context) throws Exception {
// Get the symbol from the request
String symbol = request.getParameter(“symbol”);
if ( symbol == null ) {
throw
new Exception(“You must enter a stock symbol to purchase.”);
}
Search WWH ::




Custom Search