Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

servlets

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

like image 996
Sanjeev Avatar asked Apr 07 '10 11:04

Sanjeev


People also ask

What is the difference between redirect and forward in servlet?

The Forward method forwards a request from one servlet to another resource in a web application and this resource can be another servlet, JSP page, or HTML file. The Redirect method, on the other hand, redirects the request to a different application. You cannot do this with a forward method.

What is the difference between redirect and forward?

This rule will redirect the emails as if they came directly from the original sender's email address. If you use forward, your email will be forwarded to another email address, but you will not be able to reply to the original sender.

What is the key difference between using forward () and Httpservletresponse sendRedirect ()?

(a) forward executes on the client while sendRedirect() executes on the server. (b) forward executes on the server while sendRedirect() executes on the client. (c) The two methods perform identically.

What is difference between RequestDispatcher and sendRedirect?

The RequestDispatcher interface allows you to do a server side forward/include whereas sendRedirect() does a client side redirect. SendRedirect() will search the content between the servers. it is slow because it has to intimate the browser by sending the URL of the content.


1 Answers

  • 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.

like image 52
Bozho Avatar answered Oct 05 '22 02:10

Bozho