wood burning stoves 2.0*
The moose likes Servlets and the fly likes Difference b/w RequestDispatcher in Context and request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference b/w RequestDispatcher in Context and request" Watch "Difference b/w RequestDispatcher in Context and request" New topic
Author

Difference b/w RequestDispatcher in Context and request

Srinivas Genji
Ranch Hand

Joined: May 04, 2004
Posts: 37
HI Everyone,
THere are two request dispatcher, one is in Servlet Context and other in ServletRequest. Can anyone explain when do we use either one with an example
THanks
Cheers


Genji B Srinivas<br />M.Tech (IT) Aus
chowdary Thammineedi
Ranch Hand

Joined: Aug 16, 2004
Posts: 126
It's very clear if you glance through the Servlet API.

If you use a ServletContext to get a RequestDispatcher you MUST use a STRING starting with a "/" which is interpreted as relative to the Web-Application root.

But if you use a Request to get a RequestDispatcher then the STRING you specify in the request.getRequestDispatcher("a STRING") CAN start with either a "/" or choose not do so.

Please note the difference in the above 2 paragraphs. MUST and CAN.

In case you are using a request to get a RequestDispatcher and you start off with a "/" then it is interpreted as relative to the Web-Apllication context just as it is with a ServletContext. But if you do not start with a leading "/" then the path is interpreted as relative to the request.(i.e /web-application/reuestURI/-----)
Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
Hi,

u can refer the following link

http://java.boot.by/wcd-guide/ch03s05.html

Regards
Roshini
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference b/w RequestDispatcher in Context and request