Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

Simulate Form Submission within Servlet

Hi,

I have a simple method=POST form with 3 hidden parameters. The user clicks the submit button and is directed off to the URL where some other processing occurs using the parameters.

I want to achieve exactly the same thing, but from within a servlet.

It seems possible to achieve the above using a GET method, i.e.
String newURL = "https://www.mydomain.com/cgi-bin/test?value0=tryit&value1=none&value2=some
response.sendRedirect(newURL);

However, I am not allowed to have the parameters visible in the URL. I cant help thinking that this is such a basic thing there must be an easy solution....surely it must be possible to simulate a simple form submission ?

Regards,

SMc
0
ls21gce
Asked:
ls21gce
  • 4
  • 3
  • 3
  • +1
1 Solution
 
objectsCommented:
I believe redirects can only use GET
0
 
sanjoozCommented:
Just set those variables in session and then redirect. On the other side, read them from session.
0
 
objectsCommented:
If you just want to send a POST request

http://exampledepot.com/egs/java.net/Post.html
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ls21gceAuthor Commented:
Hi,
thanks for the prompt replies...
I should have made the following clearer....

1 - I have no control over the website to which I am forwarding the USER. Only that one of the three POST parameters is a URL link back to my server. E.g. The remote site checks the parameters I pass, collects data off of the USER updates its database and then re-directs back to my server - all out of my control.

2 - Not sure, but in the example shown by objects, just sending a POST request such as shown only offers an interaction with the URL and would allow me to read the html in the response, but will not offer re-direct to the the user to achieve the aim ?

Regards,

SMc
0
 
objectsCommented:
as i said above redirects can only use GET
0
 
ls21gceAuthor Commented:
Hi,

Ok, given that the response.sendRedirect(newURL) statement from within a servlet can only use GET, does anyone have an alternative solution to the simple example I have outlined above ? I assume it must have been confronted many times before ?

Regards,

SMc
0
 
sanjoozCommented:
Take a look at curl. Java curl to be precise. You can simulate any form submission using curl.
0
 
ls21gceAuthor Commented:
Hi sanjooz,

...struggling to find documentaion on javacurl to get an overview of what it can do along with examples...might be something for the future

I think the only way I can think of achieving what I want to do is to:
1 - return back to Struts with a "FurtherActionRquired" special parameter
2 - Struts then forwards onto a jsp which contains the same automatic post form as above
3 - That form submission should then also re-direct the user to the site with callback URL
4 - Struts forwards my callback URL to servlet to complete the process.

I'm still not sure why I have to go via a JSP to achieve it.....I will try that next.

Regards,

SMc
0
 
sanjoozCommented:
0
 
ls21gceAuthor Commented:
Hi,
..just as a follow up to complete this thread.

Thanks for the various suggestions on ideas and products to help with this problem. I have now implemented the strategy I mentioned in my previous post. Although it was a bit trickier than I thought, the solution was in the steps I outlined before.

So this problem is now closed.

Regards,

SMc
0
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now