Java Reference
In-Depth Information
L ISTING 10.4
Continued
}
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
// Load the movie file
File file = new File(moviefile);
FileReader reader = new FileReader(file);
Parser parser;
out.println(“<html>”);
out.println(“<head><title>XMLServlet</title></head>”);
out.println(“<body>”);
try {
// Get an instance of the SAXParserFactory
SAXParserFactory spf = SAXParserFactory.newInstance();
// Get a SAXParser instance from the factory
SAXParser sp = spf.newSAXParser();
// Create an instance of our HandlerBase
SAXHandler handler = new SAXHandler();
// Set the Document handler to call our SAXHandler when
// SAX event occurs while parsing our XMLResource
sp.parse(new InputSource(reader), handler);
// After the resource has been parsed get the resulting table
Hashtable cfgTable = handler.getTable();
out.println(“<table align=\”center\” width=\”600\”>”);
out.println(“<caption>XML Item</caption>”);
// Print the config settings that we are interested in.
out.println(“<tr><td align=\”left\”>ID</td>” +
“<td align=\”center\”>” +
(String)cfgTable.get(new String(“ID”)) + “</td></tr>”);
out.println(“<tr><td align=\”left\”>DESCRIPTION</td>” +
“<td align=\”center\”>” +
Search WWH ::




Custom Search