• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why have two RequestDispatchers

 
Nirmala Rayudu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Why have the ServletContext's RequestDispatcher when ServletRequest's RequestDispatcher does the job? I mean the RequestDispatcher of ServletRequest can handle both request relative paths and WebApp relative paths.

Is there a legitimate reason for the existence of RequestDispatcher in ServletContext(I referred to the Servlet 2.4 Spec, it makes it sound as if ServletContext's RD was designed first, but ServletRequest's RD was designed later on to facilitate relative paths, I am wondering if this is not the case, what is the legitimate reason for existence of ServletContext's RD).

Thanks for your time,
WebApp Learner
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"WebApp Learner",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I make out of the specs:

1. ServletRequest.getRequestDispatcher() - used for absolute as well as relative paths.

2. ServletContext.getRequestDispatcher() - used only for absolute paths.

also can be used to get resources from foreign contexts using:

getContext("ContextURI").getRequestDispatcher()

which is not possible with ServletRequest.getRequestDispatcher()

those are what i think are the differences in the two. why need two...that beats me.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to point out that RequestDispatcher is an Interface, not a Class. Therefore there can be any number of classes implementing the two methods that the interface requires.
forward( request, response )
-and-
include( request, response )
Bill
 
Nirmala Rayudu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Neeraj and William for your replies.

Neeraj,
your answer raised one more question about the 'contextURI' parameter for the getContext method.

If the web-application referred to by the 'contestURI' parameter be located on another jvm, i.e does this method behave the same way in clustered environment?
 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nimala,

I hope this link is helpful in resolving a few of your doubts...
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic