Java Reference
In-Depth Information
L
ISTING
10.4
Continued
(String)cfgTable.get(new String(“DESCRIPTION”)) +
“</td></tr>”);
out.println(“<tr><td align=\”left\”>PRICE</td>” +
“<td align=\”center\”>” +
(String)cfgTable.get(new String(“PRICE”)) +
“</td></tr>”);
out.println(“<tr><td align=\”left\”>QUANTITY</td>” +
“<td align=\”center\”>” +
(String)cfgTable.get(new String(“QUANTITY”)) +
“</td></tr>”);
out.println(“</table>”);
}
catch (SAXException e) {
out.println(“Exception received: “ +
e.getMessage() + “<br>”);
}
catch (ParserConfigurationException pce) {
out.println(“Exception received: “ +
pce.getMessage() + “<br>”);
}
out.println(“</body></html>”);
}
public void destroy() {
}
}
As you can see, there is really very little difference in the application code and the servlet
code. The only noticeable differences are the way you load the
XMLResource
and the way you
output the results.
To see this servlet run, you will need to copy the
SAXHandler
class file to the
<
SERVER_ROOT
>/djs/WEB-INF/classes/
directory, copy the
item.xml
file to the
<
SERVER_ROOT
>/djs/
directory, and build
XMLServlet
. Then load the following URL into your
browser:
10
http://
yourserver
/djs/servlet/XMLServlet
You should see a page similar to Figure 10.2.