File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCA Java SE 8 Programmer I Study Guide 1Z0-808
this week in the
How to return an object instance by JSP
Joined: Nov 13, 2011
Nov 13, 2011 04:29:56
Currently I am writing a
for create the program of XML Document,
create the program is successful, but how to return this object instance?
ex: Document doc = docBuilder.newDocument();
how to return this doc by jsp??
author & internet detective
Joined: May 26, 2003
Nov 13, 2011 06:59:18
Document is a
object. It doesn't make sense to return a Java object in a browser. Instead you would return the XML character data to the user for display. (Also, this is better done in a
than a JSP. JSP is about presentation.)
OCA 8 book
How To Ask Questions The Smart Way
Blogging on Certs:
SCEA Part 1
Part 2 & 3
Core Spring 3
TOGAF part 1
Joined: Nov 13, 2011
Nov 13, 2011 08:30:08
Thanks for you answer,
Oh sorry ,I am not return a Java object in a browser.
I want to return this object "Document" for client to prase,
and that result displayed on the eclipse console,
so how should I do ?(return document object for client)
Joined: Oct 11, 2011
Nov 13, 2011 09:04:17
I have not done for xml
But if you want a json object you can use json tag library in jsp to create a json object.
Which will get by the request from the browser.
Joined: Jul 06, 2005
Nov 13, 2011 12:47:29
To return this document in a servlet:
Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //initialize StreamResult with ServletOutputStream StreamResult result = new StreamResult(response.getOutputStream()); DOMSource source = new DOMSource(doc); transformer.transform(source, result);
Thats the basic
to write the document out.
In this case is uses the servlet output stream to provide the xml response to the client.
I agree. Here's the link:
subject: How to return an object instance by JSP
XML DOC toString.
Can I pick your brains on globally accessing XML resources?
Change Encoding of XML document.
Not able to get default value of XSD element in Java object
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015