• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why have two RequestDispatchers

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nimala,

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