• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Diff getNamedDispatcher() & getRequestDispatcher()

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody explain whats the Difference between getNamedDispatcher() &
getRequestDispatcher() methods of javax.servlet.ServletContext Interface.
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Hope this Help

Thanks
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rodrigo Alvarez
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

Cheers,

Svend
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
reply
    Bookmark Topic Watch Topic
  • New Topic