I am working on struts 2.0 . I am designing a web application.
I am using Jasper Report in my application. I want to access the *.jrxml
files in my action class. I don't want to give hard coded path to the files. So to get the path dynamically I googled it and got the solution that I can get the path using getRealPath()
method. But I found two implementation of doing this:
Using
HttpSession
to get object ofServletContext
and using thegetRealPath()
method of theServletContext
object. Like this:HttpSession session = request.getSession(); String realPath = session.getServletContext().getRealPath("/");
The second approach to do it directly using the static method
getServletContext()
ofServletActionContext
. And then we can get the real path of the application using thegetRealPath()
method. Like this:String realPath = ServletActionContext.getServletContext().getRealPath("/");
Please tell me, is there any difference between the above two and also please tell me whether there is any other way to get the path?