我用JDOM做XSLT转换,在resin的环境下运行servlet,为什么会出现异常!!(在main()里,是没有错误的类)
public static void executeXSL(Document myDocument) {
try {
TransformerFactory tFactory = TransformerFactory.newInstance();
// Make the input sources for the XML and XSLT documents
org.jdom.output.DOMOutputter outputter = new org.jdom.output.DOMOutputter();
org.w3c.dom.Document domDocument = outputter.output(myDocument);
javax.xml.transform.Source xmlSource = new javax.xml.transform.dom.DOMSource(domDocument);
StreamSource xsltSource = new StreamSource(new FileInputStream("D:\\table.xsl"));
//Make the output result for the finished document
/*
* Note that here we are just going to output the results to the
* System.out, since we don't actually have a HTTPResponse object
* in this example
*/
//StreamResult xmlResult = new StreamResult(response.getOutputStream());
FileOutputStream fout=new FileOutputStream("D:\\c.html");
ByteArrayOutputStream byteArray=new ByteArrayOutputStream();
StreamResult xmlResult = new StreamResult(byteArray);//System.out
System.out.println("here");
//Get a XSLT transformer
Transformer transformer = tFactory.newTransformer(xsltSource);
//do the transform
/* transformer.transform(xmlSource, xmlResult);
byteArray.writeTo(fout);
fout.flush();
fout.close();
String str=new String(byteArray.toByteArray());
System.out.println("String Format:"+str);*/
}
catch(Exception ex){
System.out.println("Error in executeXSL"+ex);
}
}
public static Document readDocument() {
try {
SAXBuilder builder = new SAXBuilder();
Document anotherDocument = builder.build(new File("D:\\c.xml"));
return anotherDocument;
} catch(JDOMException e) {
System.out.println("readDoucment");
e.printStackTrace();
} catch(NullPointerException e) {
System.out.println("readDoucment");
e.printStackTrace();
}
return null;
}
public void init() throws ServletException {
executeXSL(readDocument());
}