Web/JSP

JSP #8 서블릿(Servlet)-2 RequestDispatcher & sendRedirect

언덕너머에 2014. 12. 29. 16:56

RequestDispatcher & sendRedirect

 

RequestDispatcher와 sendRedirect는 유사하게 동작하지만 다음의 차이점이 있다.

RequestDispatcher는 서버에서 요청한 페이지로 바로 이동하고 sendRedirect는 요청한 페이지의 정보를 클라이언트로 보낸 후 클라이언트에서 다시 서버로 해당 페이지로 이동하게 된다.

 

요약하면...

RequestDispatcher : Client Request(a.jsp) -> Server Response(a.jsp) -> b.jsp

 

sendRedirect : Cilent Request(a.jsp) -> Server Response(a.jsp) -> Client(a.jsp) Request(b.jsp) -> Server Response(b.jsp) -> b.jsp

 

결론적으로 두 매서드는 동일한 작업을 하지만 sendRedirect에 과정이 더 포함되어 있어 RequestDispatcher가 더 빠르다.