This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getNameDispatcher()

 
Ganesh.P Ram
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is getNameDispatcher() ?
And how is it different from getRequestDispatcher() ?
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public RequestDispatcher getNamedDispatcher(java.lang.String name)


Takes in a String as an argument which should be a valid servlet name mentioned in the DD. Returns a RequestDipatcher which is similar to the one returned by getRequestDispatcher. This finds its use when you define a <servlet> tag with just a name and class and without a <servlet-mapping>.

Hope this helps.

Cheers
Chandu
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

A RequestDispatcher can be obtained in three ways :
  • from the request, with getRequestDispatcher, giving a relative or an absolute path as a parameter
  • from the context, with getRequestDispatcher, giving an absolute path as a parameter
  • from the context, with getNamedDispatcher, giving a servlet name as a parameter


  • The servlet name given as a parameter to getNamedDispatcher is the name defined in the deployment descriptor :



    One BIG difference (except from the parameter) between a getRequestDispatcher obtained RD and a getNamedDispatcher obtained RD is the implicit parameters.

    When you get a RequestDispatcher (RD) from a getRequestDispatcher() method, either from the request or from the context, and you call forward() or include() method, the RD creates some implicit parameters in the request object passed as a parameter, to give informations about the original request. Informations are :


    Or the same with include instead of forward if you call the include() method.

    Well the big difference is the RequestDispatcher you obtain vi the getNamedDispatcher() method does NOT create these implicit parameters.

    Hope it helps you.

    EDIT : you can find infos about this (and others) in the servlet spec summary i wrote (SRV.8 for RequestDispatcher). See Servlet Spec Summary link in my sig.
    [ March 16, 2006: Message edited by: Frederic Esnault ]
     
    Chandra Sagi
    Ranch Hand
    Posts: 162
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thats a good explaination.

    Thanks
    Chandu
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic