Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

redirect a post to another post at external URL

 
Andrew Gibb Sr
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an httpservlet class, and I receive a post request in the doPost method of that response.

I want to basically do a response.sendRedirect(newURL) but I want to use the POST method instead of the GET method. I need to use POST because my parameters are larger than 2 KB, and that is the size limit for URLs on most browsers.

The newURL is an EXTERNAL URL on a different host, so from what I've heard I can't use a forward with the getrequestdispatcher method, because that only works within the current servlet's context.

I've seen some solutions using a proxy-type setup, where I would open up a new urlconnection within the servlet, and just funnel the results back to the response object. This seems like it would be a bit complex and I'm not sure it would work.

Is there any simple way of using the response object to redirect a POST request? Like using the flushbuffer method, or writing the parameters to the header or body...?
 
Harsha Ka
Ranch Hand
Posts: 45
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure about this, but think you can use httpclient to do a post to the new URL.
 
Tim Moores
Bartender
Posts: 2734
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A redirect always uses GET, no way around that. You could certainly do a programmatic POST to the remote server from within your servlet (no proxy needed for that, and the HttpClient library would indeed be useful for that), but then you'd have your URL in the client browser instead of the remote server's URL, and any user interaction with the resulting page -if any- would need to go through your servlet, essentially necessitating you to write a proxy. So it depends a bit on what the overall goal is.
 
Anurag Verma
Ranch Hand
Posts: 167
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
agreed with Tim (Redirection is always a GET). Another option could be something like redirect the user to another URL even before displaying that form & let that application display the form. This is applicable only if you are the owner of second application as well. Otherwise, Tim has already answered it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic