使用POST参数重定向FacesContext

使用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>