aspose file tools*
The moose likes XML and Related Technologies and the fly likes URGENT!!!! Xalan problem in Servlet with JRun Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "URGENT!!!! Xalan problem in Servlet with JRun" Watch "URGENT!!!! Xalan problem in Servlet with JRun" New topic
Author

URGENT!!!! Xalan problem in Servlet with JRun

Nehal Dave
Greenhorn

Joined: Dec 22, 2000
Posts: 28
i am trying to implement the servlet sample which comes along with Xalan jar file. the servlet code is as follows:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
/*
* This sample applies the todo.xsl stylesheet to the
* todo.xml XML document, and returns the transformation
* output (HTML) to the client browser.
*
* IMPORTANT: For this to work, you must place todo.xsl and todo.xml
* in the servlet root directory for documents.
*
*/
public class SimpleXSLTServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException, java.net.MalformedURLException
{
// The servlet returns HTML.
response.setContentType("text/html; charset=UTF-8");
// Output goes in the response stream.
PrintWriter out = response.getWriter();
try
{
TransformerFactory tFactory = TransformerFactory.newInstance();
// Get the XML input document and the stylesheet.
Source xmlSource = new StreamSource(new URL("http://localhost:8100/fooparam.xml").openStream());
Source xslSource = new StreamSource(new URL("http://localhost:8100/fooparam.xsl").openStream());
// Generate the transformer.
Transformer transformer = tFactory.newTransformer(xslSource);
// Perform the transformation, sending the output to the response.
// transformer.transform(xmlSource, new StreamResult(out));
}
catch(MalformedURLException e)
{
out.write(e.getMessage());
e.printStackTrace(out);
}
catch (Exception e)
{
out.write(e.getMessage());
e.printStackTrace(out);
}

out.close();
}

}
fooparam.xml is
<?xml version="1.0"?>
<doc>Hello</doc>
fooparam.xsl is
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl aram name="param1" select="'default value'"/>
<xsl:template match="doc">
<html>
<head><title>Stylesheet parameter</title></head>
<body>
<h2>XML source</h2>
<p><xsl:value-of select="."/></p>
<h2>Stylesheet parameter</h2>
<p>The param1 stylesheet parameter has been set to <xsl:value-of select="$param1"/>.</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I have included xerces.jar & xalan.jar in the classpath of JRun.
following is the error when i try to access the servlet
Namespace not supported by SAXParserjavax.xml.transform.TransformerConfigurationException: Namespace not supported by SAXParser at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:764) at SimpleXSLTServlet.doGet(SimpleXSLTServlet.java:104) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service .......
Please help me !!!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12821
    
    5
I think this may be due to a separate classpath being used for user servlets. Look at the property named "user.classpath" in the local.properties file for your application.
Which version of JRun is this?
Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: URGENT!!!! Xalan problem in Servlet with JRun