Producing an HTML using XSL file from Java Servlet

G

G.C.

Hello,

I want to write a java servlet to produce an html file. Instead of
writing an html file directly, I want to write a xml file describing
the html file, then process it using an xsl file.
Here is the main part:

public void doPost(HttpServletRequest request, httpServletResponse
resp)
throws IOException, ServletException
{

PrintWriter pout = resp.getWriter();

pout.println("<?xml version=\"1.0\"?>");
pout.println("<?xml-stylesheet type=\"text/xsl\"
href=\"test.xsl\"?>");
pout.println("<FitnessCenter>");
pout.println("<Member>");
pout.println("<Name>Jeff</Name>");
pout.println("</Member>");
pout.println("</FitnessCenter>");
}

As far as I understand, the xml is written directly to a web browser,
and automatically processed by test.xsl.
The problem is I get a "The XML page cannot be displayed" error
message. I checked and it looks like the browser cannot find the xsl
file.
I used the command "context.getRealPath("test.xsl")" to see where it
excepts to find the xsl file, and put the file there, but still I get
the same message. Do you have any idea why? where should I put the xsl
file?!!!

Thanks,
GC
 
A

Arnaud Berger

Hi,

What about switching the access logs of your server on (if they aren't
already) ?

Then, you will probably see which url has been called by the browser to get
text.xsl

Regards,

Arnaud
 
A

Abrasive Sponge

Also, set the mimeType..resp.setContentType("text/xml");

the browser may still not recognize it as an xml doc.
 

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

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top