This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Pass parameters with 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 » JSP
Bookmark "Pass parameters with response.sendRedirect" Watch "Pass parameters with response.sendRedirect" New topic
Author

Pass parameters with response.sendRedirect

Manjusha Harimadhavan
Greenhorn

Joined: Oct 18, 2010
Posts: 2
Hi,

I have website A and website B, both are of the same company. Users of website A can currently login to website A only from website A. Now, we are developing a feature wherein users will be able to login from the login page of website B also. When users try to login from website B, we first validate the user using a web service and if the user is authentic, we should redirect him/her to website A along with a token which would be evaluated by website A and would let the user directly login.

I use response.sendRedirect("http://websiteA?tokenID=12345");

Everything goes as it should except that the parameter token ID is not passed to website A always. To be more precise, it is present in the JSP page in alternate runs. If I close the browser and open it again, the parameter would not be there. But if I run it again, it would be there. I know it has got to do something with response.sendRedirect, but I haven't been able to find an alternate to this.

Please note that the URL will be absolute since both websites are in different servers altogether.

This is a very urgent requirement and any help would be very much appreciated.

Thanks!
Senthil Manoharan
Greenhorn

Joined: Mar 01, 2010
Posts: 28
Hi,

I think you can use JspForward instead of response.redirect.

Here is the syntax for the jsp:forward

<jsp:forward page={"URL" } >
<jsp:param name="parameterName"
value="{parameterValue }" />
</jsp:forward>

One disadvantage is that the url will be same once you forward it to another page (URL of the forward page won't be there)

Thanks and Regards
Senthil Kumar M
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Everything goes as it should except that the parameter token ID is not passed to website A always. To be more precise, it is present in the JSP page in alternate runs. If I close the browser and open it again, the parameter would not be there. But if I run it again, it would be there. I know it has got to do something with response.sendRedirect, but I haven't been able to find an alternate to this.


The response.sendRedirect() sends the entire url in the redirect and that includes any query params you have. I would suggest that use a browser tool like Httpfox or LiveHeaders to inspect the headers in the response.

Are you sure you are not accessing a cached page of website A when you open a new browser?


Senthil Manoharan wrote
I think you can use JspForward instead of response.redirect.


It is not possible to 'forward' outside the context of the current application.



Manjusha Harimadhavan
Greenhorn

Joined: Oct 18, 2010
Posts: 2
Thanks for the replies!

response.sendRedirect itself works. The problem was because of something else in the JSP which was redirecting to another place based on some other condition.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Pass parameters with response.sendRedirect
 
Similar Threads
Differences btwn (response.sendRedirect) and (Requestdispatcher.forward)
Session expire problem with HttpSessionListener
common URL Mapping for filter
Log Out Problem
Problem in implementing Single Sign on