struts2 jaspers shows FileNotFoundException

流过昼夜 提交于 2019-12-12 06:47:54

问题


I am trying to integrate jasper with struts2 by using the following tutorials.

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

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

(shows Error saving file: jaspers\jasper\our_compiled_template.jrxml)

I went through many suggestions , but I failed to correct it . .


回答1:


getRealPath() is the answer.

So i changed above code as below and got output

ServletContext context=ServletActionContext.getServletContext();

String path= context.getRealPath("/jasper/our_jasper_template.jrxml"); 


来源:https://stackoverflow.com/questions/20782928/struts2-jaspers-shows-filenotfoundexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!