Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 ways of getting a RequestDispatcher

 
Rajiv Chelsea
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I correct, ServletContext's getRequestDispatcher(String path) method has the absolute path/url as argument!
 
Rajiv Chelsea
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's correct

Are there any advantages we get by getting requestDispatcher from
ServletContext?
 
Sudipta Laha
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a method getContext(string) in servletContext which can be used to get the foreign context. so we can use the method getRequestDispatcher to get the RequestDispatcher for resources in foreign context. But when we use the request.gerRequestDiapatcher method we get the RequestDispatcher of the current context only.
So the servletContext requestDispatcher may be helpful in some scenarios.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic