使用POST参数重定向FacesContext [英] FacesContext redirect with POST parameters

查看:116
本文介绍了使用POST参数重定向FacesContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用POST参数将页面重定向到外部站点,但是我不能使用香草HTML <form action="url">,如此处所述:

I need to redirect page into external site with POST parameters, but I cannot use vanilla HTML <form action="url"> like it is explained here:

JSF commandButton-将POST参数传递到外部站点

因为该表单将在jsf表单内-并且它不起作用.

because then the form would be within a jsf form - and it doesn't work.

是否可以使用:

FacesContext.getCurrentInstance().getExternalContext().redirect("http://example.com");

具有POST参数而又没有其他原始形式的

?或者,也许还有其他方法可以在没有形式的情况下实现这一目标?

with POST parameters without additional vanilla form somehow? Or maybe there is other way to acheive this without form?

推荐答案

尝试如下操作:

JAVASCRIPT:

JAVASCRIPT:

function redirect() {
    document.getElementById("mySubmitButton").submit();
}

XHTML:

<h:form>
     <span onclick="javascript:redirect()" class="linkClass">REDIRECT</span>
</h:form>

<div style="display:none:"> <!-- If you want it hidden -->
    <form action="http://external/myplace.html" method="post"> 
        <input type="hidden" value="value1"></input>
        <input type="submit" id="mySubmitButton"</input>
    </form>
</div>

添加了另一个测试.

通过动态参数:

在这个例子中,我们假设我们总是要发送一个值.

In this example we assume that we are always going to send a value.

JAVASCRIPT:

JAVASCRIPT:

function redirect(dynamicValue) {
    document.getElementById("dynamicField").value = dynamicValue;
    document.getElementById("mySubmitButton").submit();
}

XHTML:

<h:form>
     <span onclick="javascript:redirect('myValue')" class="linkClass">REDIRECT</span>
</h:form>

<div style="display:none:"> <!-- If you want it hidden -->
    <form action="http://external/myplace.html" method="post"> 
        <input id="dynamicField" type="hidden" value=""></input>
        <input type="hidden" value="value1"></input>
        <input type="submit" id="mySubmitButton"</input>
    </form>
</div>

这篇关于使用POST参数重定向FacesContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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