struts2 jaspers显示FileNotFoundException [英] struts2 jaspers shows FileNotFoundException
本文介绍了struts2 jaspers显示FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下将jasper与struts2集成教程。
但jasper编译器无法访问该文件,我的代码如下:
But the jasper compiler not able to acess the file and my code is given below
ServletContext context=ServletActionContext.getServletContext();
URL is = context.getResource("/jasper/our_jasper_template.jrxml");
String path=is.getPath();
String jasper = is.getPath().replace("our_jasper_template.jrxml", "our_compiled_template.jasper");
System.out.println(path); //here displays the path
JasperCompileManager.compileReportToFile(path,jasper); // here throws FileNotFoundException
如果我更改 path =C:\\ \\ new_jasper_template.jrxml
(保留文件),
编译器读取文件,但无法将文件保存到 our_compiled_template.jasper
If I change the path="C:\our_jasper_template.jrxml"
(keeping file there),
compiler reads file, but fails to save file to our_compiled_template.jasper
(显示保存文件时出错:jaspers\jasper \ new_compiled_template.jrxml
)
我经历了很多建议,但我未能纠正。 。
I went through many suggestions , but I failed to correct it . .
推荐答案
getRealPath()
就是答案。
所以我改变了上面的代码,得到了输出
So i changed above code as below and got output
ServletContext context=ServletActionContext.getServletContext();
String path= context.getRealPath("/jasper/our_jasper_template.jrxml");
这篇关于struts2 jaspers显示FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文