Skip to Content
avatar image
Former Member

Hi All! I have to generate xml file using servlet

Hi

File(File adapter)-- >XI ->J2EE application(HTTP Receiver adapter).

I get an xml file to my J2EE application. In my servlet i have to generate the xml file as it is and display it in a browser. How to generate the xml file using servlet.

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    May 15, 2006 at 05:06 PM

    Hi

    please have a look at the test code which generates a static xml code , might be the change reqd here is that the request you are getting is xml which has to be passed to the response object

    public class test extends HttpServlet

    {

    public void doGet

    (

    HttpServletRequest req, // This provides information sent by the browser

    HttpServletResponse res // This is used to send information back to the browser

    ) throws

    ServletException, // General exception that should be thrown if there

    // is a unrecoverable error in the Servlet

    IOException

    {

    // Set the MIME type for the information being sent to the browser.

    // In this case, we are going to send back HTML

    <i> <b> res.setContentType( "text/xml" );</b></i>

    // Get a reference to the output stream.

    // Anything written to this stream is sent directly to the browser

    // (The browser sees this as its input).

    ServletOutputStream out = res.getOutputStream();

    // The following println statements create an HTML page.

    // Notice that the <html></html>, <head></head>, and <body></body>

    // tags are all properly formed HTML syntax.

    out.println("<?xml version=\"1.0\"?>" );

    out.println("<?xml:stylesheet type=\"text/xsl\" href=\"file:///c:/servlets/test.xsl\"?>");

    out.println("<persons>");

    out.println("<person><firstname>Oren</firstname><lastname>Ben-KiKi</lastname></person>");

    out.println("</persons>");

    }

    }

    hope this helps , please mark helpul answers

    regards

    rajeshkr

    Add comment
    10|10000 characters needed characters exceeded