Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning an XML Document from an EJB

Status
Not open for further replies.

jigsu

Programmer
Jun 1, 2003
1
US
Hi,

I have a requirement where I have to write a EJB which converts database entries into XML document and returns that document to a JSP page.The JSP page will then apply a XSLT stylesheet to the document.I have written the code but for some reason it is not working.I will be grateful if someone can help me on this issue.

My EJB is a stateless session bean which has the following business method:

public Document getWeblogXML(String username)
{
Document document = null;

// code to get reference to a Entity bean and get records through a finder method and get iterators (omitted here)

// code to generate the XML document

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();

Element root = (Element) document.createElement("Journal");
document.appendChild(root);
while(i.hasNext())
{
JournalEntry jentry = (JournalEntry) PortableRemoteObject.narrow(i.next(),JournalEntry.class);
Element weblog = (Element) document.createElement("weblog");
root.appendChild(weblog);
Element date = (Element) document.createElement("date");
weblog.appendChild(date);
date.appendChild(document.createTextNode(jentry.getDate()));
.. similarly generate remaining nodes ...
}
return document;
}

And the JSP page has following code:

<%
Document document = x.getWeblogXML(username);
TransformerFactory tFactory = TransformerFactory.newInstance();
File stylesheet = new File(style);
//style is the name of the xsl stylesheet
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = tFactory.newTransformer(stylesource);
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new File(&quot;htmlout.html&quot;));
transformer.transform(source, result);
%>
<%@ include file=&quot;htmlout.html&quot; %>


I am using J2EE RI from Sun.The application deploys and even runs without error.but I get a blank page in the browser when I try to run the JSP page.There must be something wrong with what I am doing, but I am not able to find out.I will appretiate any help in this matter.

Thanks,
Jigsu.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top