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 Diff  getNamedDispatcher() & getRequestDispatcher() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Diff  getNamedDispatcher() & getRequestDispatcher()" Watch "Diff  getNamedDispatcher() & getRequestDispatcher()" New topic
Author

Diff getNamedDispatcher() & getRequestDispatcher()

Purujit Saha
Ranch Hand

Joined: Nov 01, 2005
Posts: 86
Can anybody explain whats the Difference between getNamedDispatcher() &
getRequestDispatcher() methods of javax.servlet.ServletContext Interface.
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi

Hope this Help

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
Hi,

The difference is the accpetable values of the String argument:

ServletContext.getRequestDispatcher(String arg1)
ServletContext.getNamedDispatcher(String arg2)

arg1 must be an absolute URL (starting with a '/') targeting a valid servlet or jsp file. This URL being associated to the servlet with a <servlet-mapping> element in the DD

arg2 must be the name of a servlet, as given by the <servlet-name> sub-element of the <servlet> element of the DD.

Note that you also have

ServletRequest.getRequestDispatcher(String arg3)

=> arg3 may be both a relative (not starting with '/') or relative (to this request) URL.


Cheers


It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
Hello "gaspode..."-

Welcome to JavaRanch.

On your way in you may have missed that JavaRanch has a policy on display names, and yours does not comply with it - please adjust it accordingly, which you can do right here. Thanks for your prompt attention to this matter.

Enjoy your time here.


Ping & DNS - my free Android networking tools app
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
Hi,

Ok, corrected, sorry for the inconvenience. I hope the new one is acceptable

Cheers,

Svend
Steven Colley
Ranch Hand

Joined: Feb 18, 2005
Posts: 290
But the mainly difference between these methods is that the "getNamedDispatcher()" method from (ServletContext interface) does not add some request "attributes" to the request operation. It means that the included or forwarded page are not able to get some attributes from the request sent.

Attributes:

javax.servlet.include.request_uri
javax.servlet.include.servlet_path
javax.servlet.include.context_path

javax.servlet.forward.request_uri
javax.servlet.forward.servlet_path
javax.servlet.forward.context_path
javax.servlet.forward.query_string

and another aside here:
* it does not take a forwad slash. (runtime error).

Hope it help you!!

cya!


SCJP | SCWCD | SCBCD | SCWSD 5 | SCEA (I) 1.4 | SCEA 5 | IBM SOA 669
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Diff getNamedDispatcher() & getRequestDispatcher()