• 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic