Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Producing html from XML+XSL thru servlet .  RSS feed

Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • 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 javax.servlet.http.*;
import javax.servlet.*;
public class AccountDemo extends HttpServlet
public void doGet(HttpServletRequest rq,HttpServletResponse rs)throws ServletException,IOException
PrintWriter p=rs.getWriter();
XmlDocument result = new XmlDocument();
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);
OutputStream out = new FileOutputStream("account1.html");
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.
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • 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!?!?
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>

author of:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!