Chapter 15
610
if (name.compareTo("location") == 0) {
curLocation = lastParsedText;
}
if (name.compareTo("price") == 0) {
curPrice = lastParsedText;
}
if (name.compareTo("trip") == 0) {
workString = curLocation + "--" + curStartdate + " for "
+ curDuration + "--**$" + curPrice + "**";
myDeals.addElement(new TravelDeal(curID, curRegion, curCommission,
workString));
}
}
}
These are all the classes on the client. Before you can compile them successfully, however, you must
make that the aelfred.jar file is in your classpath. You should copy the JAR file the same directory
as the applet's classes:
> javac -classpath .;.\aelfred.jar VacationApplet.java
This completes our examination of the client-side classes. They will all be loaded into the browser from
the vacserv\ directory. Let us turn our attention to the server-side classes.
Supplying XML Data: VacationServlet Classes
The first class we examine is the simplest: the VacationServlet class. You can find the source code
in the projavaxml\vacserv\WEB-INF\classes directory. This servlet class handles the HTTP GET
method and supplies an XML document (sell-offs) in return.
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletConfig;
import java.io.OutputStream;
import java.io.IOException;
import com.wrox.pjxml.*;
public class VacationServlet extends HttpServlet {
public DealsFinder myFinder;
public void init(ServletConfig conf) throws ServletException {
myFinder = new DealsFinder();
myFinder.init();
}
Client calls are received through the HTTP GET method. Here, we extract the tnum parameter from the
request, and use it to fetch all the trip descriptions that needs to be returned. Most of the work is
performed by the locateDealsXML() method of the com.wrox.pjxml.DealsFinder class.