JSF:我想在动作bean内发送POST请求 [英] JSF : I want to send POST request inside action bean

查看:151
本文介绍了JSF:我想在动作bean内发送POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动作bean方法:

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.
}

所以我应该保存数据,并通过POST重定向到带有某些参数的外部系统页面

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

我希望你能帮助我.

推荐答案

发送HTTP 307重定向.假设您仍在使用JSF 1.x:

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();

但是,这将在客户端发出一个(非JSF相关的)安全确认警告,并询问该站点是否可以将输入的数据重新发送到另一个站点.

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.

但这不会更改URL,客户会认为他仍在您的网站上.

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

这篇关于JSF:我想在动作bean内发送POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆