开发者

java servlet: difference between send redirect and forward in servlets [duplicate]

This question already has answers here: 开发者_如何学Python RequestDispatcher.forward() vs HttpServletResponse.sendRedirect() (9 answers) Closed 6 years ago.

I am using servlet there is two method redirect and forward both are send request to the same page but what is the difference between them.any idea


  • redirect - it uses a browser redirect. It sends an http response with code 3xx (see wikipedia), and then the browser makes another request to the new page

  • forward - forward is internal for the servlet container. The browser never understands that the page has changed. Hence the URL doesn't change (like with redirect), and you have the same request in the new page as well.


To add to the points written above, Redirect means at Client side and forward means at server side. So It means that one can redirect its page to some other application from the current application because it's hapening at browser side but in forward the it forward to some jsp or servlet for the same application.


In case of Request Dispatcher request is not return to browser & it directly forward to page(servlet) from current servlet(page). So the browser url is not change. While in case of Send Redirect first request is return to browser from current page(servlet) & then forward to the specified(page). So the url is change.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜