This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes 2 ways of getting a RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "2 ways of getting a RequestDispatcher" Watch "2 ways of getting a RequestDispatcher" New topic
Author

2 ways of getting a RequestDispatcher

Rajiv Chelsea
Ranch Hand

Joined: Jun 15, 2010
Posts: 88


What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

If I correct, ServletContext's getRequestDispatcher(String path) method has the absolute path/url as argument!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Rajiv Chelsea
Ranch Hand

Joined: Jun 15, 2010
Posts: 88
That's correct

Are there any advantages we get by getting requestDispatcher from
ServletContext?
Sudipta Laha
Ranch Hand

Joined: Aug 23, 2010
Posts: 49
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.


Regards,
Sudipta Kumar Laha
 
 
subject: 2 ways of getting a RequestDispatcher
 
Similar Threads
How To Call Two Different Classes From the Main Program Using the Same API?
Home interface or Home Interface stub
Time Capsule
Writing an Interface
Regarding Interfaces