What is the relationship between ServletContext and RequestDispatcher? I found this code fragment doing some research. ServletContext sc = getServletContext(); RequestDispatcher rd = sc.getRequestDispatcher(url); rd.forward(req,res); Why do you need a ServletContext here?
ServletContext holds all the information about the web application context your servlet is executing in. Any requests for servlet engine functions such as request dispatch have to go through this context. Sun's design tries to make each web application independent from every other application the server may be dealing with. The servlet API - downloadable from java.sun.com - deals with this organization. Bill ------------------ author of:
I'm just curious if anyone here has the servlet/jsp specifications with them. I have an application where the entire directory structure is pulled dynamically from some EJBs, that uses a servlet which matches a path something like this: /site/* When I forward the request to a jsp page, the request parameters are forwarded, but the path info is not, and the uri is changed to point to the jsp page. I would think that forwarding would just pass the request and response as-is to the jsp page, but apparently it has other plans. This is in Tomcat. What should the 'official' behavior be?