• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • 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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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