Wednesday, September 26, 2007

dispatcher.forward() and response.sendRedirect()

dispatcher.forward()

This will forward all the request parameters to the jsp/servlet mentioned in
RequestDispatcher dispatcher=request.getRequestDispatcher("/Coreservlet");

But the url in the browser will remain the same.


response.sendRedirect()

This will forward all the request parameters to the jsp/servlet mentioned in
response.sendRedirect("/MVC2practice/Coreservlet");

But the url in the browser will not remain the same.

With a sendRedirect(), the only way to pass data is through the session or with web parameters (url?name=value). It does not handle request parameters here as done in "dispatcher.forward(req,res);"

No comments: