Skip to main content

Posts

Showing posts with the label RequestDispatcher

What is the difference between RequestDispatcher's forward method and HttpServletResponse's sendRedirect method?

RequestDispatcher's forward(ServletRequest request, ServletResponse response)   The forward() method of RequestDispatcher will forward the ServletRequest and ServletResponse that it is passed to the path that was specified in getRequestDispatcher(String path) . The response will not be sent back to the client and the web container (For example, Tomcat) internally redirects the request to the other JSP/Servlet. Remember , you can redirect only to a page within current servlet context. The client will not know about this change of resource on the server. The forward works better when one resource(JSP/Servlet) must perform business logic and share the results with another resource(JSP/Servlet). Because the request and response are forwarded to another resource all request parameters are maintained and available for use. Forward request, happened on server side, is transparent to the client (browser). Therefor, no history of it will be stored on the client, so using the back ...