JSF: Redirect to url as POST not as GET

ε祈祈猫儿з 提交于 2019-11-27 02:48:50

问题


I have an JSF page that redirects via context.getExternalContext().redirect(url); where the url is sth. like login.jsf?token=foobar

What I want now is to send the token via POST not via GET request. So that it doesn´t show up in the url, is this possible with JSF?


回答1:


It's not possible with HTTP, so also not with JSF. There are however several ways to achieve the requirement.

Put it in the session scope. In the bean behind the redirected page, read and remove it from the session scope. Or when you're using JSF 2.0, use the flash scope.

Forward to a page containing a POST form pointing to the desired URL, having the token as hidden input value and include some JS code which does form.submit() on page load.




回答2:


Yes you can do this by redirecting your backing bean to some temporary page which contain all hidden values and use form.submit(); Example:

Backing Bean:

public String submitValue() {
        return "temp";
}

temporary.jsf

<h:form id="JsfTemp" prependId="false">
  <h:outputText id="welcomeOutput" value="Test Sending form"/>
  <h:inputHidden id="Merchant_Number" value="#{paymentBean.paymentDetails.merchantNumber}" />
</h:form>
</body>

<script type="text/javascript">
  function submitPage() {
    document.getElementById("JsfTemp").action="http://localhost:9090/TestClient/HelloWorld";
    document.getElementById("JsfTemp").submit();
  }
  submitPage();
</script>


来源:https://stackoverflow.com/questions/5405718/jsf-redirect-to-url-as-post-not-as-get

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