Client-Side Presentation Logic
611
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String tripno = req.getParameter("tnum");
int tripNumber = 0;
if (tripno != null) {
try {
tripNumber = Integer.parseInt(tripno);
} catch (Exception ex) {
tripNumber = 0;
}
}
String tpXML = myFinder.locateDealsXML(tripNumber);
byte[] byteAry = tpXML.getBytes();
res.setContentLength (byteAry.length);
OutputStream output = res.getOutputStream();
output.write (byteAry);
output.flush ();
}
The RDBMS to XML Mapper: DealsFinder Class
The DealsFinder class fields the remote call from the VacationApplet, and co-ordinates the retrieval
of data from the JDBC data source, and the conversion of this data into XML format for the return value.
The main purpose of this class is to handle the locateDealsXML() method, typically called remotely.
Other than the VacationServlet class we have just looked at, the rest of the server-side classes are in
a package called com.wrox.pjxml. This packaging facilitates the reuse of these classes, for the JSP
example that we will be looking at later.
package com.wrox.pjxml;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
public class DealsFinder {
queryBean myQuery;
public DealsFinder() {}
The init() method makes the required JDBC connection. This is typically called from the init()
method of a servlet or JSP.
public void init() {
try {
myQuery = new queryBean();
myQuery.makeConnection();
} catch (Exception e) {}
}