Question

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 . .

Was it helpful?

Solution

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"); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top