JSP sendRedirect() and getRequestDispatcher()

If this post was helpful to you, please leave a comment. :) Thank you!

response.sendRedirect() :

[index.jsp]








[redirect.jsp]





browser screen : null

[process]
browser >> request(index.jsp) >> webServer >> response(index.jsp) >> browser(sendRedirect) >> request(redirect.jsp) >> webServer >> response(redirect.jsp) >> browser

: when sendRedirect method runs, browser asks for redirect.jsp again. so request object is not shared.


request.getRequestDispatcher() :

[index.jsp]








[redirect.jsp]





browser screen : requestAttribute

[process]
browser >> request(index.jsp) >> webServer >> index.jsp(forward > redirect.jsp) >> redirect.jsp(receive - response, request) >> response(redirect.jsp) >> browser

: when getRequestDispatcher method runs, webServer container forwards request, response object(in index.jsp) to redirect.jsp. so request and response object is shared.

Comments