Change the <form>
to <h:form>
and other HTML components to JSF components, bind their values with your managed bean and let the user submit the data. Then, in your action
method you evaluate the data and then use a library like Apache HttpClient to send a POST request to the URL you want/need.
This could be a raw example of this (based on your example).
JSF code
<h:form >
<h:inputHidden value="#{bean.aField}" />
<h:commandButton value="Submit" action="#{bean.anAction}" />
</h:form>
Managed bean code
@ManagedBean
@RequestScoped
public class Bean {
private String aField;
//constructor, getter and setter...
public void anAction() {
//do your form processing...
HttpRequestHandler httpRequestHandler = new HttpRequestHandler();
httpRequestHandler.handlePost(...); //send the arguments here
}
}
public class HttpRequestHandler {
public void handlePost(String ... parameters) {
//you do the Apache HttpClient POST handling here
//always create a class between your application and your third party libraries
//code adapted from HttpClient examples: http://hc.apache.org/httpcomponents-client-ga/examples.html
HttpClient httpclient = new DefaultHttpClient();
try {
HttpPost httpPost = new HttpPost(...);// your URL goes here
//do as you please with the HttpPost request
} finally {
httpclient.getConnectionManager().shutdown();
}
}
}
If you don't want to add the Apache HttpClient library for this job, then you could use native Java classes like URLConnection
as shown here: Using java.net.URLConnection to fire and handle HTTP requests