You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Bryan Kearney <bk...@avolent.com> on 2002/10/08 00:51:57 UTC

RE: SAX Filter Output in Servlet

You need to get the output writer from the servlt response, then set the
mime type and and content length on the response.

-- bk


> -----Original Message-----
> From: Bruce McDougald [mailto:bmcdougald@hotmail.com]
> Sent: Monday, October 07, 2002 4:55 PM
> To: xalan-j-users@xml.apache.org
> Subject: SAX Filter Output in Servlet
> 
> 
> I am having a problem sending html output as an http response 
> from my SAX
> transform.  I'm getting output to the system console when I 
> use System.out
> for my OutputStream, but thats no good for what I need.  From 
> the XALAN
> documentation, I'm supposed to
> create a PrintWriter object, but that is not compatable to 
> the Serializer
> object created in my SAX transformation code.
> 
> Can anyone tell me how to redirect the HTML output created from the
> serializer object back to the servlet?
> 
> Thanks.
> 
> Bruce
> 
> --------------------------------------------------------------
> ---------
> Here's my code:
> --------------------------------------------------------------
> ---------
>  ...
>       PrintWriter out = servletresponse.getWriter();
> 
>       XMLReader reader = XMLReaderFactory.createXMLReader();
> 
>       SAXTransformerFactory saxTFactory = ((SAXTransformerFactory)
> tFactory);
> 
>       XMLFilter xmlFilter1 = new SAXParse();
> 
>       xmlFilter1.setParent(reader);
> 
>       XMLFilter xmlFilter2 =
>                saxTFactory.newXMLFilter(new
> StreamSource("http://localhost/taymac.nsf/dynitmact.xsl"));
> 
>       xmlFilter2.setParent(xmlFilter1);
> 
>       // xmlFilter2 outputs SAX events to the serializer.
>       Serializer serializer = SerializerFactory.getSerializer
> 
> (OutputProperties.getDefaultMethodProperties("html"));
> 
>       serializer.setOutputStream(out);    // <--- System.out 
> was here in the
> example, but I need output to go back as servlet response!!!!!!
> 
>       xmlFilter2.setContentHandler(serializer.asContentHandler());
> 
>       xmlFilter2.parse(new
> InputSource("d:\\notes\\data\\domino\\cgi-bin\\itmact.xml"));
> ...
> 

Re: SAX Filter Output in Servlet

Posted by Bruce McDougald <bm...@hotmail.com>.
> You need to get the output writer from the servlt response, then set the
> mime type and and content length on the response.
>
> -- bk
>

Ok, then how do I (i.e. what call do I make) redirect the output to the
browser?

Do I say something like

servletResponse.setContentType("text/html; charset=UTF-8");
PrintWriter out = servletResponse.getWriter();
...
//Processing:
//  Filter1: Parse XML
//  Filter2: Transform XML using SAX
...
out.print();

??????