dcsimg
return a String from a java class in the AJAX
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   scott_jsn
Posted On:   Monday, January 14, 2008 03:36 PM

I have a question regarding return a String from a java class in the AJAX process: factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); ... ByteArrayOutputStream baos = new ByteArrayOutputStream(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); //Up to this point, it is all the same. But at the end of the function, there are two ways to return a string: (I) t.transform(new DOMSource(doc),new StreamResult(baos)); //The transform(...) is the last line of the function } (II) t.transfor   More>>

I have a question regarding return a String from a java class in the AJAX process:

factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();

Document doc = builder.newDocument();
...

ByteArrayOutputStream baos = new ByteArrayOutputStream();

TransformerFactory tf = TransformerFactory.newInstance();

Transformer t = tf.newTransformer();

//Up to this point, it is all the same. But at the end of the function, there are two ways to return a string:

(I)

t.transform(new DOMSource(doc),new StreamResult(baos));
//The transform(...) is the last line of the function
}


(II)

t.transform(new DOMSource(doc),new StreamResult(baos));
response.getOutputStream().println(xmlString);[/b]
//The .println(...) is the last line of the function
}


--So, what is the difference between (I) and (II)? I mean in (I) the document is returned as a String via t.transform(new DOMSource(doc),new StreamResult(baos)); While in (II) the String is returned via response.getOutputStream().println(xmlString). Why so?

   <<Less

Re: return a String from a java class in the AJAX

Posted By:   Anonymous  
Posted On:   Monday, February 11, 2008 07:39 AM

please format it and make it readable
About | Sitemap | Contact