Producing an HTML using XSL file from Java Servlet

Discussion in 'Java' started by G.C., Apr 18, 2005.

  1. G.C.

    G.C. Guest

    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
    G.C., Apr 18, 2005
    #1
    1. Advertising

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


    "G.C." <> a écrit dans le message news:
    ...
    > 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
    >
    Arnaud Berger, Apr 18, 2005
    #2
    1. Advertising

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

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

    G.C. wrote:
    > 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
    >
    Abrasive Sponge, Apr 18, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Holyer
    Replies:
    0
    Views:
    1,986
    Andy Holyer
    Apr 12, 2006
  2. circuit_breaker
    Replies:
    2
    Views:
    1,996
    Jack Jia
    Apr 4, 2004
  3. arachno
    Replies:
    0
    Views:
    835
    arachno
    Jun 25, 2003
  4. Replies:
    1
    Views:
    3,600
    A. Bolmarcich
    May 27, 2005
  5. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help with XSL/XSL:FO for producing revision indicator bar in document.

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Apr 28, 2006, in forum: XML
    Replies:
    6
    Views:
    573
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    May 3, 2006
Loading...

Share This Page