h:outputLink将上下文路径前缀为URL值

时间:2014-03-27 21:14:47

标签: jsf tomcat jsf-2

我有一个h:outputLink,如下所示:

<h:outputLink value="#{doc.value}" style="color:blue">#{doc.key}</h:outputLink>

该值是一个URL www.example.com。当我点击该值时,我在地址栏中看到的网址是http://localhost:8080/Project/www.example.com。为什么上下文路径以URL为前缀?

我查找了生成的HTML,但该值是没有上下文路径的实际URL。我在JSF中尝试了<a>,但没有区别。

任何帮助解决这个问题将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:3)

<h:outputLink /> 如果值字段是相对路径,则将其值附加到当前父路径(而不是Servlet上下文)。这意味着如果您在http://localhost:8080/Project/users.xhtml中有此特定链接:

<h:outputLink value="sales.xhtml">
    Sales
</h:outputLink>

这会尝试将您重定向到http://localhost:8080/Project/sales.xhtml

好吧,因为你指定了一个相对的,JSF知道它必须将它附加到你当前的父URL。为了避免这种情况,请写下绝对URL:

public String getValue(){
    return "http://www.example.com";
}
<h:outputLink value="#{doc.value}">
    Custom external url
</h:outputLink>
相关问题