applet?
So if user types http://mysite/customerlist.xml, the request goes into
the customerlist generator servlet. I have customerlist generator
function in another file to create the customerlist.xml. But how to
connect xml file with the servlet? In customerlist generator, File file
= new File (where should I specify the customerlist.xml path?).
> So if user types http://mysite/customerlist.xml, the request goes into
> the customerlist generator servlet. I have customerlist generator
> function in another file to create the customerlist.xml. But how to
> connect xml file with the servlet?
In web.xml, the same way you connect any other URL path to a Servlet.
> In customerlist generator, File file
> = new File (where should I specify the customerlist.xml path?).
If you're dynamically generating the information every time it's requested,
why write it to a File at all? Just use the 'response' object to send it
out to the client.
--
Wendy Smoak
She's (Wendy) right you know.
> --
> Wendy Smoak
>
>
DOMSource domSource = new DOMSource(xml); //xml is a DOM tree.
File F = new File ("customerlist.xml");
TransformerFactory tff = TransformerFactory.newInstance();
Transformer serializer = new tff.newTransformer();
StreamResult srOut = new StreamResult(tff);
serializer.transform(domSource, srOut);
So I am using DOM and then serialize it to XML. So the servlet will
call this code to generate 'customerlist.xml' on the fly. So how to
connect 'response' object with srOut and then display
'customerlist.xml' out to the client without writing it to a File?
Why not just serialize the XML directly to the response stream? Writing
to a file only makes sense if you're caching the results and not
re-generating it every time.