Image

Imageseaofsin wrote in Imagejava_dev

Hello. I'm trying to write a servlet that will get the name of a XML file from a form and then parse that file using Sax and upload the information to a database. I've got an application written that will parse a XML file and upload it, but I'm having trouble converting it to a servlet. I guess what I'm having trouble with is actually setting up/coding the parser, if that makes sense.

This is what I have for my application:

// Use an instance of ourselves as the SAX event handler
DefaultHandler handler = new myParser();

SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter(System.out, "UTF8");

// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(argv[0]), handler);

} catch (Throwable t) {
t.printStackTrace();
}


I just need some way to change this so I can use it in a servlet.