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 lose request object when using response.sendRedirect() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "lose request object when using response.sendRedirect()" Watch "lose request object when using response.sendRedirect()" New topic
Author

lose request object when using response.sendRedirect()

dhriti joshi
Ranch Hand

Joined: Aug 13, 2002
Posts: 82
for redirecting a url i am using response.sendRedirect ,but in this case I lose the request object and can not retrieve the request object and request attributes on my resulting url.
kindly suggest what can i use to get thr request attributes.
thanks.
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi,
you can use RequestDispatcher.forward method to forward request some other resource where request will be available in forwarded page.
Thanks
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
When you do a request.sendRedirect(), you are sending the response back to the client, and the client akes another request to fetch the redirect URL. Since this becomes a separate request, and the first request ends once the redirect is sent back to the client, that request object and and hence its attributes are lost.

to overcome this:
1. use the method described in the above post. use RequestDispatcher.forward or RequestDispatcher.include

2. if using redirect is necessary, u will have to send the request attributes manually as hidden form fields and retrieve them in the next servlet/JSP OR put the attributes in the session.
 
 
subject: lose request object when using response.sendRedirect()
 
Similar Threads
sending values in Header using sendRedirect
How to change the URL when the servlet forwards the page?
How Stop code execution in JSP
RequestDispatcher vs Response.sendRedirect
Passing resultset from Servlet to JSP