aspose file tools*
The moose likes Servlets and the fly likes servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets" Watch "servlets" New topic
Author

servlets

nastik pandit
Greenhorn

Joined: Feb 08, 2009
Posts: 2
guys, we can forward request using request's or context's requestDispatcher.In which case we will use request, and in which case we will use context? also whats the difference between / and ../. Please help
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61191
    
  66

First, a few things that will help you out here on the Ranch.

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "servlets" in a forum completely dedicated to questions on Servlets isn't very helpful.

Please go back and change your post to add a more meaningful subject by clicking the

Secondly, not everyone who helps people out here is a "guy".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anutosh Swamy
Ranch Hand

Joined: Sep 20, 2007
Posts: 30

Dear Krishna,

We can forward a request either by using the RequestDispatcher() of ServletContext interface or the ServletRequest interface, the point when to use ServletContext or ServletRequest is that the ServletRequest looks for the resources in the same context (same webapp) to which the invoking servlet belongs.

Moreover the pathname used in the RequestDispatcher() of ServletContext must begin with a "/" which is an absolute path.

The pathname used in the RequestDispatcher() of ServletRequest interface can be an absolute path or a relative path means it can start with “/” or “../..”.

K. Anutosh<br /> <br />SCJP 1.4<br />SCWCD 1.4<br />OCA (Paper I)
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
That kind of questions are usually answered in the API docs.

http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRequestDispatcher(java.lang.String)
http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRequestDispatcher(java.lang.String)

Please familiarize yourself with the API docs and learn to find/understand them.

Edit: links fixed, UBB parser didn´t seem to take the last parenthesis in the generated URL.
 
 
subject: servlets