This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I would like to forward the user from my web app to a different one. I need to pass some parameters with "POST" to a different site(http:/foo.com). The requestDispatcher only takes context relative paths and the response.redirect does not allow POST or any data to be sent.
How can I do this? [ October 20, 2005: Message edited by: Pete Neu ]
If you are using JSP technology, try to use the JSP JSTL core tag <c:redirect>
Make sure you have the JSTL Library in your class path.
Otherwise, if you using Servlet to do the cross context redirection, I believe that best is to create the url yourself like the following:
SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
Joined: Feb 18, 2005
Thanks for the many answers. The problem I still can't solve is that I need to do a POST response. Meaning: I don't want the user to see that I return the parameters to the other server. Elsewhise the user could manipulate them or destroy them
[ October 20, 2005: Message edited by: Pete Neu ] [ October 20, 2005: Message edited by: Pete Neu ]
You can't redirect with a post response. The requestDispatcher.forward method only works within your context. The response.sendRedirect method works by sending a 302 response header to the browser (which causes it to make a new GET request).
You could make the post from the server using either URLConnection or Apache's HttpClient, get the results, and then redirect to the other site.
The second approach may cause popup warnings that the page is trying to take you to a different site; especially if you're under SSL.
Thanks for the many answers. The problem I still can't solve is that I need to do a POST response. Meaning: I don't want the user to see that I return the parameters to the other server.
Sorry, I misunderstood your requirement at first.
Well, it's possible to redirect the POST request. Check out the following:
This will use HTTP 307 status code to redirect your request with it's Body content. sendRedirect uses other code to redirect, which cause the Body to be discarded. This method works under IE, but i'm not sure how other browser will handle this 307 code.
Eddy, That's a great tip. I just tried it with Firefox and it worked.
The browser did warn me with a popup message saying "This web page is being redirected to a new location. Would you like to resend the form data that you have typed to the new location?" but that's to be expected. I didn't try under SSL which tends to have it's own layer of warnings.