Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

RequestDispatcher

 
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three ways to obtain RequestDispatcher object,

1.RequestDispatcher dispatch = request.getRequestDispatcher("string")
2.RequestDispatcher dispatch = getServletContext().getRequestDispatcher("/string")
3.RequestDispatcher dispatch = getServletContext().getNamedDispatcher("string")


can anyone explain the thrird one?how it is differ from the other two?
Should we study it for the exam?

Thanks
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


3.RequestDispatcher dispatch = getServletContext().getNamedDispatcher("string")



This method take the servlet name as parametere. The servlet name is definded in web.xml as <servlet-name>. The request is dispatched to that corresponding servlet.

The getRequestDispatcher methods sets the folloing request attributes while transfering the request in case of include.

javax.servlet.include.request_uri :
javax.servlet.include.context_path :
javax.servlet.include.servlet_path :
javax.servlet.include.path_info :

For the forwrod method it set the same arrtibutes , but the names have forword instead of include.

The getNamedDispatcher not set these attributes.

Hope this help

Thanks
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vinod,

In addition:

1.RequestDispatcher dispatch = request.getRequestDispatcher("string")
- "string" can be a relative path or not to a particular resource. (i.e. jsp, servlet, etc.)
2.RequestDispatcher dispatch = getServletContext().getRequestDispatcher("/string")
- "/string" must NOT be a relative path. Which means you must start with a forward slash always...
3.RequestDispatcher dispatch = getServletContext().getNamedDispatcher("string")
- "string" must be a servlet name defined in the DD.

Hope this somehow helps.
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good explanation!!

Thanks Narendra,Richard.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!