General J2EE: Difference between getRequestDispatcher () of ServletContext and
What is the difference between getRequestDispatcher () of ServletContext and ServletRequest
- Posted by: Server Side
- Posted on: September 02 2004 14:32 EDT
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 by Krishna Kurra on September 02 2004 23:58 EDT
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).
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,
thanks for the help Sravi