Servlet and Output

Discussions

EJB design: Servlet and Output

  1. Servlet and Output (1 messages)

    Hello!!I have a problem with Servlet, I have a Document, from a DB, and I need to print it with an XML file.

    my code..

    .
    .
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
        Document doc = docBuilder.newDocument();
        Element root = doc.createElement("DATABASE");
    .
    ..
    .
    doc.appendChild(root);
          OutputStream outStream = new FileOutputStream("DataBase.xml");
          OutputFormat format = new OutputFormat(doc);
          Serializer serializer = SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(outStream, format); serializer.asDOMSerializer().serialize(doc.getOwnerDocument());
          outStream.flush();
          outStream.close();

    This is right when I use it in a main(), but in Servlet I had problems with the OutFormat.. debug OK, but it doesn't work!!

    Someone have a solution..
    Thank you

    CARLO

    Threaded Messages (1)

  2. Servlet and Output[ Go to top ]

    I am not sure exactly what you want to achieve. Do you want to serialize the DOM document to Servlet output? If so, you'd need to obtain output stream or writer from Servlet Response object, set content type to xml and then serialize the DOM using this output stream.