This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sendRedirect() using post data from jsp  RSS feed

 
John Holme
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally, I would use response.sendRedirect(url) to navigate the user to another page, with form data attached as a query string. However, there are parts of my query string that I don't want to display in the browser's location bar after the redirect is done. Since response.sendRedirect() uses the GET method to request the url, the entire query string is displayed in the location bar.
I've tried using HttpURLConnection (using setRequestMethod("POST")), and it retrieves the contents of the url (which I can then out.print() to my jsp). Trouble is, the url is a vendor's url, so all the relative links are broken when I do that (because the browser still thinks it's at the origin url).
It seems like there might be a way to do this using HttpURLConnection.getOutputStream(), but I can't figure it out.
Is there any way to set the request method of the redirect to POST prior to using response.sendRedirect()? Is there any other method, routine or functionality I can use to navigate the user to a remote url with POST data?
Your kind assistance is most sincerely appreciated!
[ April 10, 2003: Message edited by: John Holme ]
 
Geeta Ramasami
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Instead of redirecting if u r establishing a url connection to the page to which u r trying to redirect, then u can use HttpUrlCOnnection and use the following:
huc1.setRequestMethod("POST");
huc1.setRequestProperty("name",value);
where huc1 is a HttpUrlConnection Object.
But as u r redirecting there is one option.
U can write the request values as name/value pair to a file(say txt or xml).Then redirect the user to the new url.
There u can read it from the file.If u r redirecting to url of a different host, then to read the file whoch has got the request data use socket connection to establish the connection to the remote host.
This is just an idea..U can look in for someother best way of doing.
Cheers
Geeta
 
John Holme
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geeta, nice thought, but the remote url is that of a vendor, so I can't implement any code on the receiving end to read from the file.
I'm working up a solution that uses javascript to open a window, write and post the form, then close the window *really quick* so the user can't intercept my confidential data. It's an ugly hack! ...and not very secure. :roll:
There's *got* to be a solution to this problem using Java; the requirement for sending form data in post format using a re-direct is not *that* unusual...
 
Debashish Chakrabarty
Ranch Hand
Posts: 231
Firefox Browser Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I am not missing something here..how about using the jsp forward action?
 
John Holme
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forwards only work relative to the webapp's document root; you can't forward to a remote url.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!