Question

What is the benefit of using the servletContext as opposed the request in order to obtain a requestDispatcher?

servletContext.getRequestDispatcher(dispatchPath)

and using

argRequest.getRequestDispatcher(dispatchPath)
Was it helpful?

Solution

It's there in the javadocs in black and white

http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRequestDispatcher(java.lang.String)

The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a relative path.

OTHER TIPS

When you call getRequestDispatcher from ServletContext, you need to provide an absolute path, but for ServletRequest objects, you need to provide a relative path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top