【发布时间】:2017-09-26 05:15:30
【问题描述】:
我的 xslt 文件位于包结构 com/test/application/meta/xslt/forgotPassword.xslt
TransformerFactory tFactory = TransformerFactory.newInstance();
Source xslDoc = new StreamSource("/com/test/application/meta/xslt/forgotPassword.xslt");
Source source = new StreamSource(new StringReader(getXmlData()));
try {
Transformer transformer = tFactory.newTransformer(xslDoc);
StringWriter writer = new StringWriter();
transformer.transform(source, new StreamResult(writer));
String output = writer.toString();
return output;
}
catch (Exception e)
{
e.printStackTrace();
}
出现错误:
FATAL ERROR: '/com/test/application/meta/xslt/forgotPassword.xslt (No such file or directory)'
当我尝试使用时
Source xslDoc = new StreamSource("com/test/application/meta/xslt/forgotPassword.xslt");
我收到此错误:
FATAL ERROR: '/var/lib/tomcat7/com/test/application/meta/xslt/forgotPassword.xslt (No such file or directory)'
如何将正确的文件位置传递给 Transformer ?该文件位于 com/test/application/meta/xslt/forgotPassword.xslt
谢谢
【问题讨论】:
标签: java xml xslt path filepath