문제

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

도움이 되었습니까?

해결책

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"); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top