generate sitemap dynamically w/o using servlet

U

usgog

I will stick with servlet. :)

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?).
 
W

Wendy Smoak

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.
 
J

Joan

Wendy Smoak said:
In web.xml, the same way you connect any other URL path to a Servlet.


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.

She's (Wendy) right you know.
 
U

usgog

My home project code is like the following:

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?
 
U

usgog

My home project code is like the following:

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?
 
A

Alan Krueger

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top