tags:

views:

349

answers:

1

Hi. I am developing a dynamic web project j2ee web application using eclipse. I have an existing jasper report file in .jrxml format found in web-inf/jasperreports folder. How do I access these files from my java classes in the src folder. I am not even sure if context path is the right term for the root folder of the application so please enlighten me too on this part.

I am using by the way spring webflow. how do i get or initialize the object servlet context

+2  A: 

ServletContext.getRealPath method can be used to get the context path. ServletContext.getRealPath("/") returns the webapp root path. Path for WEB-INF/jasperreports would be:

ServletContext sc = getServletContext();
String reportPath = sc.getRealPath("/WEB-INF/jasperreports");

You can initialize you java classes from a Servlet of ServletContextListener where you can get reference for ServletContext by respectively the inherited getServletContext() and the servletContextEvent.getServletContext().

Chandra Patni
To be more precise: the `getRealPath()` "converts" a relative webcontent path to an absolute disk file system path, which you can further use in the usual `java.io` stuff. On the other hand, you can also use `getResource()` or even `getResourceAsStream()` here.
BalusC
I am using spring's webflow. How do i get or initialize the object ServletContext in the flow.
cedric