struts2 jaspers shows FileNotFoundException

357 views Asked by At

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

There are 1 answers

0
mahesh On BEST ANSWER

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");