What is the difference between getRequestDispatcher () of ServletContext and ServletRequest
Please explain in easy to understand language and explain with a simple working example.
Please explain from latest J2EE version.
I want to understand when to use ServletContext and when to use ServletRequest's dispatcher call
-
Difference between getRequestDispatcher () of ServletContext and (2 messages)
- Posted by: Server Side
- Posted on: September 02 2004 14:32 EDT
Threaded Messages (2)
- Difference between getRequestDispatcher () of ServletContext and by Krishna Kurra on September 02 2004 23:58 EDT
- Thats great by Vijaya Sravanthi on April 17 2008 16:35 EDT
-
Difference between getRequestDispatcher () of ServletContext and[ Go to top ]
- Posted by: Krishna Kurra
- Posted on: September 02 2004 23:58 EDT
- in response to Server Side
From Javadoc
The servletRequest's getRequestDispatcher() can take a relative path while
ServletContext's getRequestDispatcher() can not(can only take relative to the
current context's root).
For example
with ServletContext both
-> request.getRequestDispatcher("./jsp/jsppage.jsp") - evaluated relative to the path of the request
-> request.getRequestDispatcher("/jsp/jsppage.jsp") - evaluated relative to the root
are all valid
with ServletContext only
-> context.getRequestDispatcher("/jsp/jsppage.jsp") is valid
but not context.getRequestDispatcher("./jsp/jsppage.jsp").
that is it can not evaluate a path other than context root.
As said in Javadoc servletContext's requestDispatcher must begin with a "/" and is interpreted as relative to the current context root.
Hope this helps,
Krishna -
Thats great[ Go to top ]
- Posted by: Vijaya Sravanthi
- Posted on: April 17 2008 16:35 EDT
- in response to Krishna Kurra
thanks for the help Sravi