Send an HTTP POST request to an external site using <h: form>
I want to send an HTTP request to another server using the component <h:form>.
I can send a POST request to an external site using the HTML component <form>, but the component <h:form>does not support this.
<form action="http://www.test.ge/get" method="post">
<input type="text" name="name" value="test"/>
<input type="submit" value="CALL"/>
</form>
How can I achieve this with <h:form>?
+5
1 answer
<h:form> . <h:form> URL- . , , JSF. , , . .
<form>. HTML JSF.
: , , , zip , -, , .
JSF <h:form> - API , ZIP InputStream (, Reader, , zip , ), HTTP ExternalContext#getResponseOutputStream() :
public void submit() throws IOException {
InputStream zipFile = yourWebServiceClient.submit(someData);
String fileName = "some.zip";
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
ec.responseReset();
ec.setResponseContentType("application/zip");
ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
OutputStream output = ec.getResponseOutputStream();
try {
byte[] buffer = new byte[1024];
for (int length = 0; (length = zipFile.read(buffer)) > 0;) {
output.write(buffer, 0, length);
}
} finally {
try { output.close(); } catch (IOException ignore) {}
try { zipFile.close(); } catch (IOException ignore) {}
}
fc.responseComplete();
}
. :
+6