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.
开发者_Python百科I am using by the way spring webflow. how do i get or initialize the object servlet context
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()
.
精彩评论