File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "RequestDispatcher " Watch "RequestDispatcher " New topic
Author

RequestDispatcher

MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
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


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
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


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Richard Rex
Ranch Hand

Joined: Sep 19, 2005
Posts: 100
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.


"If you fail to plan, you plan to fail."<br /> <br />Chad<br />SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3<br />SCDJWS (next)
MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
Good explanation!!

Thanks Narendra,Richard.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher