我正在使用jsf 2.我在facelet文件中有一个指向外部URL的链接.我当前的观点是/app1/home.xhtml与啊:commandLink有这样的动作
<h:commandLink value="#{link}" action="#{action.redirect}" target="_blank"/>
Run Code Online (Sandbox Code Playgroud)
action.redirect重定向到的url是/app2/info.do.但是,似乎JSF尝试将url的扩展名更改为.xhtml.然后失败并显示错误消息.
com.sun.faces.context.FacesFileNotFoundException:/app2/info.xhtml在ExternalContext中找不到资源
我如何才能正确重定向?
不要在<h:commandLink>这里使用,这是错误的标签.它旨在提交一个JSF POST表单并导航到一个JSF视图,这两个你显然不希望在这个特定的用例中发生.
只需使用<h:outputLink>甚至纯HTML <a>.所以,
<h:outputLink value="#{action.redirect}" target="_blank">#{link}</h:outputLink>
Run Code Online (Sandbox Code Playgroud)
要么
<a href="#{action.redirect}" target="_blank">#{link}</a>
Run Code Online (Sandbox Code Playgroud)
请注意,您不需要<h:form>两种方法.