File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Work of sendRedirect() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Work of sendRedirect() method" Watch "Work of sendRedirect() method" New topic
Author

Work of sendRedirect() method

Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34
Hi all,

I have studied about sendRedirect() method and i got some point like -

If client send a request, it goes to server or container. Container calls the servlet but this servlet is unable to handle the request. so, it send the request to different servlet using sendRedirect method. This response goes to browser with status code so, browser see the status code and create a new request with new URL and send to the container for the request. So, all this thing happen internally. Client does not know what is going internally. Client see the proper output only.

i understood this thing only. so it is right and wrong.

Thanks in advance
Abahy
Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
what you understand is right ..its perfect....

When forward is used we can pass data to the forwarded jsp/servlet using request.setAttribute() as the same request and response objects available the forwarded servlet/jsp. But using sendRedirect() we have to set the data in session or by appending the data to the URL that will be passed as argument to this method, because by calling this method a new request is created.

The forward() request is transparent to the user. It is done at server side and it is not visible to user.

The sendRedirect is not transparent to the user, if request is sendRedirect then its visible in your browser (redirect at client side).

The forward() method is faster than using sendRedirect as no network round trip to the server and back is required.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
Note that forward only works within a web app, generally not across web apps, and certainly not across servers. In those cases you can only use redirect.


Ping & DNS - updated with new look and Ping home screen widget
Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34
I got idea

Thanks a lot
 
jQuery in Action, 2nd edition
 
subject: Work of sendRedirect() method
 
Similar Threads
Send Redirect
Use of getRequestDispactcher()
Doubts on buffers, committing response (with RequestDespatcher, sendError)
What is difference between RequestDispatcher() and sendRedirect()?
difference between request.getRequestDispatcher(),response.sendRedirect()