Chapter 15
604
where nnn is the latest trip number seen by the client. The application on Tomcat that will hold the
application is called /vacserv. The simplest way to do this is to create the following directory structure
in the webapps\ directory in Tomcat:
webapps\
vacserv\
WEB-INF\
classes\
The applet will then read the content of the URL into a String, and return it to the caller. This effectively
hides all IO operations from the caller. We also define the methods mentioned earlier for the applet:
private String locateDealsXML(int tripNum) {
String resp;
URL myURL;
try {
URL tpURL = getDocumentBase();
myURL = new URL(tpURL.getProtocol(),
tpURL.getHost(),
tpURL.getPort(),
"/vacserv/servlet/locatedeals?tnum=" + tripNum);
InputStream myStream = myURL.openStream();
StringWriter myWriter = new StringWriter();
int c;
while ((c = myStream.read()) != -1)
myWriter.write(c);
myWriter.close();
resp = myWriter.toString();
} catch (Exception e) {
resp = e.toString();
}
return resp;
}
The filterList() method performs filtering on the curDeals vector. It clears the listbox, and
repopulates it with a filtered list of deals. The filtering is based on the currentRegionFilter and the
minCommission.
private void filterList() {
tripList.removeAll();
if (currentRegionFilter == 0) {
for (int i = 0; i < curDeals.size(); i++) {
TravelDeal tpDeal = (TravelDeal) curDeals.elementAt(i);
if (tpDeal.getCommission() >= minCommission) {
tripList.add(tpDeal.getDescription());
}
}
} else {
for (int i = 0; i < curDeals.size(); i++) {
TravelDeal tpDeal = (TravelDeal) curDeals.elementAt(i);