• Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher

 
Rohan Kayan
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between a RequestDispatcher object obtained from the Request object and the RequestDispatcher object obtained from the ServletContext ?
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ServletRequest.getRequestDispatcher() method can accept paths relative to the current request (paths that don't start with a slash).

Paths passed to the ServletContext.getRequestDispatcher() method must start with a slash (and are therefore relative to the web app root.)
 
Daniel Dalton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You MUST use context relative URLs with the one from the ServletContext (beginning with /), while you MAY use a URL relative to the current servlet (ommitting the /) as well as context relative with that from ServletRequest.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!