[英]How to give absolute “file-path” in a java class of a web application?
在本地计算机(localhost)上,在Web应用程序的Java类文件中,给出的文件路径如下。
JRBeanCollectionDataSource bean = new JRBeanCollectionDataSource(al);
try {
print = JasperFillManager.fillReport("D://vivek's//powerSpace//report//bus.jasper",
new HashMap(), bean);
} catch (JRException e) {
e.printStackTrace();
}
return al;
}
但是,当此Web应用程序托管在服务器上时,如何给出文件的绝对路径。
为此使用资源。
例如:
将bus.jasper放入您的Web应用程序的resources文件夹中,然后使用:
InputStream resource = getClass().getClassLoader().getResourceAsStream("bus.jasper");
并从那里使用InputStream。
如果您使用的类的API非常la脚,则需要使用文件路径
ConstantDataManager.class.getClassLoader().getResource("bus.jasper").getPath();
第二种解决方案在Weblogic上效果不佳。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.