aspose file tools*
The moose likes Servlets and the fly likes redirect to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "redirect to servlet" Watch "redirect to servlet" New topic
Author

redirect to servlet

Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
I want to redirect to another servlet from one servlet and I am using response.sendRedirect(url) method without sending params through query string.
Can anybody tell me still how I am getting those parameters in second servlet using request.getParameter().
I am using weblogic8.1 sp5 and servlet2.3

Thanks in advance
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Till the client doesn't get response, the request doesn't die (I mean, request will be same whether you are forwarding or redirecting it to other web resource) so you get the same parameters in all the web resources untill the request is responded.
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
If so, Then why RequestDispatcher is used, as we can get params if in the same session.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The short answer is, you can't.

The sendRedirect method sends a 302 header to the browser which indicates that it should make a new request with the given URL. The only way to add parameters to that request is with query string parameters.


There is, however, a way that you can ask the browser to make the original request (with the original POST method and the original form parameters) to the new URL by setting the response code to 307 and setting the location manually:



I just tried this and it worked but FireFox created a popup warning to let me, the user, know that this site is trying to redirect the entire form to a new URL.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
Hi Ben, thanks for your reply, But my question was without sending parameters thru query string or not setting response code as you said I am getting those params. Is this because of as - rathi said. Then why should one use Req. Dispatcher method.

Thanks again for reply.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by rathi ji:
request will be same whether you are forwarding or redirecting it to


This is false.
A redirect results in a new request being issued from the browser.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Deepa More:
Hi Ben, thanks for your reply, But my question was without sending parameters thru query string or not setting response code as you said I am getting those params. Is this because of as - rathi said. Then why should one use Req. Dispatcher method.

Thanks again for reply.


Check to see what status code Weblogic sends when you call sendRedirect.
It could be that it's using 307.
You can do this with the LiveHTTPHeaders plugin for FireFox.

If you're interested in learning more about the 302 and 307 status codes, see:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Ben Souther:


This is false.
A redirect results in a new request being issued from the browser.


Thanks Ben for correcting me and sorry Deepa, my point is valid only for forward.
[ August 18, 2006: Message edited by: rathi ji ]
 
 
subject: redirect to servlet