如何使用JSF创建简单的重定向? [英] How to create a simple redirect with JSF?

查看:52
本文介绍了如何使用JSF创建简单的重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jsf创建简单的重定向?

How do I create a simple redirect with jsf?

我尝试过:

    <h:form>
        <h:commandButton action="www.google.de" value="go to google" />
    </h:form> 

但是,当我单击按钮时,我只是停留在索引页面上.没发生什么事!怎么了?

But when I click the button, I just stay on the index page. Nothing happens! What is wrong here?

推荐答案

在这里JSF绝对必要吗?您似乎根本不需要向您提交任何内容.只需使用纯HTML.

Is JSF absolutely necessary here? You don't seem to need to submit anything to your side at all. Just use plain HTML.

<form action="http://www.google.de">
    <input type="submit" value="Go to Google" />
</form>

请注意,指向外部站点的URL必须包含方案( http://部分),否则它将仅相对于当前请求URI提交,例如http://example.com/context/www.google.de .

Please note that the URL to the external site must include the scheme (the http:// part), otherwise it would just be submitted relative to the current request URI, such as http://example.com/context/www.google.de.

如果您确实需要屈服于您,例如进行预处理和/或记录某些内容,则可以在操作方法中使用 ExternalContext#redirect().

If you really need to submit to your side, e.g. to preprocess and/or log something, then you could use ExternalContext#redirect() in the action method.

<h:form>
    <h:commandButton value="Go to Google" action="#{bean.submit}" />
</h:form>

使用

public void submit() throws IOException {
    // ...

    FacesContext.getCurrentInstance().getExternalContext().redirect("http://www.google.de");
}

这篇关于如何使用JSF创建简单的重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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