• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Producing html from XML+XSL thru servlet .

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
I hv written a servlet which shd throw an html BY PROCESSING xml+xsl as follows.
import org.xml.sax.SAXException;
import com.sun.xml.tree.*;
import com.jclark.xsl.dom.Transform;
import com.jclark.xsl.dom.TransformEngine;
import com.jclark.xsl.dom.TransformException;
import com.jclark.xsl.dom.XSLTransformEngine;
import org.xml.sax.InputSource;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class AccountDemo extends HttpServlet
{
public void doGet(HttpServletRequest rq,HttpServletResponse rs)throws ServletException,IOException
{
try
{
System.out.println("hello");
rs.setContentType("text/html");
PrintWriter p=rs.getWriter();
System.out.println("hello1");
XmlDocument result = new XmlDocument();
System.out.println("hello2");
new XSLTransformEngine()
.createTransform(XmlDocument.createXmlDocument (new InputSource( new FileInputStream("http://localhost:8082/servlet/account.xsl") ), false) )
.transform(XmlDocument.createXmlDocument(new FileInputStream("http://localhost:8082/servlet/account.xml"),false), result);
System.out.println("hello3");
OutputStream out = new FileOutputStream("account1.html");
System.out.println("hello4");
result.write(out);
out.close();
}
catch(Exception e){}
}
}
I am running this prog thru TOMCAT on port 8082.But the servlet is processed upto "hello2" only.
It means either it is not accessing the file account.xml& xsl FROM THE WEB-INF/CLASSES dir where servlet is resideing.I hv also tried putting the xml+xsl in ROOT.But still it is not processed.
Can anyone help me solving this.Its very important for me as this will save me creating separate XSL for netscape as servlet will throw an HTML which can be viewed thru netscape also.
By,
Manish
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why in the name of Alan Turing do people keep doing this?
You have a perfectly good
} catch( Exception e )
in exactly the right place and you ARE NOT USING IT!?!?
Sheesh!
At the very least
e.printStackTrace( System.out ); or
e.printStackTrace( p ) ;
but Java's exception mechanism provides such better facilities! You could have a whole chain of catch blocks to do specific debugging statements. For instance - what specialized exceptions are you going to see from the XSLTransformEngine methods?
Some exceptions thrown by a parser can point to the line number and character that caused a problem! <rant>Use those Exceptions people!</rant>
Bill

------------------
author of:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic