File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes ServletContext and RequestDispatcher? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContext and RequestDispatcher?" Watch "ServletContext and RequestDispatcher?" New topic
Author

ServletContext and RequestDispatcher?

Shuaib Gill
Ranch Hand

Joined: May 29, 2001
Posts: 62
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?


programmer77
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
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:
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletContext and RequestDispatcher?