cedric
cedric

Reputation: 3147

Getting Context path

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

Upvotes: 0

Views: 8205

Answers (1)

Chandra Patni
Chandra Patni

Reputation: 17587

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

Upvotes: 2

Related Questions