JSF : I want to send POST request inside action bean

你。 提交于 2019-12-23 05:29:16

问题


I have an action bean method:

public void submitForm() {
// here bean save some information about input data in local DB
saveEnteredData();
//  I should redirect to external system page with post params.
}

So i should save data and make a redirection into page of external system with some params by POST

I hope that you'll help me.


回答1:


Send a HTTP 307 redirect. Assuming that you're still on JSF 1.x:

FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.setStatus(307);
response.setHeader("Location", "http://other.com");
facesContext.responseComplete();

This will however issue a (non-JSF-related) security confirmation warning at the client side with the question whether the site may resend the entered data to the other site.

If you dislike this warning, then there's no other option than to play for proxy yourself.

URLConnection connection = new URL("http://other.com").openConnection();
connection.setDoOutput(true); // POST
// Copy headers if necessary.

InputStream input1 = request.getInputStream();
OutputStream output1 = connection.getOutputStream();
// Copy request body from input1 to output1.

InputStream input2 = connection.getInputStream();
OutputStream output2 = response.getOutputStream();
// Copy response body from input2 to output2.

This will however not change the URL and the client thinks he's still on your site.



来源:https://stackoverflow.com/questions/4913289/jsf-i-want-to-send-post-request-inside-action-bean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!