posted 18 years ago
Hi !
A RequestDispatcher can be obtained in three ways :
from the request, with getRequestDispatcher, giving a relative or an absolute path as a parameterfrom the context, with getRequestDispatcher, giving an absolute path as a parameterfrom 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 ]
SCJP 5 - SCWCD 1.4 - SCBCD 1.3 - Certification study documents/resources: http://esnault.frederic.free.fr/certification