Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

redirect to servlet

 
Deepa More
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If so, Then why RequestDispatcher is used, as we can get params if in the same session.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepa More
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic