Difference between JSP forward and redirect.

Difference between JSP forward and redirect.


Ref:http://stackoverflow.com/questions/6068891/difference-between-jsp-forward-and-redirect


Explanation_01:

  • redirect sets the response status to 302 [1], and the new url in a Location header, and sends the response to the browser. Then the browser, according to the http specification, makes another request to the new url.
  • forward happens entirely on the server. The servlet container just forwards the same request to the target url, without the browser knowing about that. Hence you can use the same request attributes and the same request parameters when handling the new url. And the browser won’t know the url has changed (because it has happened entirely on the server).

Explanation_02:

I’ve heard interesting explanation of redirect and forward. Imagine that you need some service from your friend.Its doesn’t matter what service. Suppose that your friend can’t help you but know who can.

He would REDIRECT your request if he will tell you: “I can’t handle this but know who can.Here his phone number. Call him”.

He would FORWARD your request if he will tell you: “No problem” and call that man by himself without noticing you about involving another person in handling your desire. Then your friend wil get result of soring out your wish and transmit to you.


Explanation_03:

  • Redirect:
    1.User requests a resource.
    2.Response sent to the user.
    3.This is not the requested resource, this is response with HTTP code 302 and contains the URL of the requested resource.
    4.URL could be same or different from the requested URL.
    5.Client browser makes request for resource again with the new URL, this time the actual resource is sent to the user.

  • Forward:
    It is the process of simply displaying the requested resource to the user. It happens entirely on the server side.


by Mike Sun, March 22, 2017;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值