File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher

 
MInu
Ranch Hand
Posts: 517
  • 0
  • 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
 
Narendra Dhande
Ranch Hand
Posts: 951
  • 0
  • 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
 
Richard Rex
Ranch Hand
Posts: 100
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good explanation!!

Thanks Narendra,Richard.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic