Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

Forward to different URL and pass parameters

 
Pete Neu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello,

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 ]
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi





I hope, it will help you. try this

bye for now
sat
 
ashok sashrith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Report post to moderator
try this,

Forward your request to a temporary html within your application. And while loading the html(in onload), forward it again to the different site (http:/foo.com) and retrieve your data.
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Report post to moderator
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:

 
Pete Neu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 ]
 
Vijay Jagannathan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator
To elaborate on what Eddy said, use the c:redirect as follows:



Cheers
Vijay
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.

Or

This is a little more of a hack (because it depends on Javascript at the browser side).
Redirect to a page of your own that has the form in it (with the action pointing to the other site) and use the Javascript onload event to submit the form.

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.
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Report post to moderator

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.

Hope it works.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.

Thanks.
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Report post to moderator
Just glad it works.
 
mshaikh shaikh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Ben,
Can you explain how you did it??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
THis has already been covered in your other post.
 
    Bookmark Topic Watch Topic
  • New Topic