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("htmlout.html");
transformer.transform(source, result);
%>
<%@ include file="htmlout.html" %>
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.
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("htmlout.html");
transformer.transform(source, result);
%>
<%@ include file="htmlout.html" %>
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.