I am trying to call a Struts action from simple, standalone Java class.
The Struts action uses FormFiles to receive file uploads.
I am reading about URLConnection and HttpURLConnection, but am not sure how to proceed.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general form submission is just an HTTP POST request with parameteres.
It gets generated by your java standalone class and sent to the server, the server proceeds this request and then redirects it to Struts.
However I wouldn’t use here directly the low-level java API since it doesn’t implement the HTTP protocol.
If putting an additional jar to your project is not an issue, I suggest you to use
Apache HTTPClient project
Here is an example (much more simple than it would be with HttpConnection):
Example