h:outputLink将上下文路径添加到URL值的前缀 [英] h:outputLink prefixes context path to a URL value
问题描述
我有一个h:outputLink
,如下所示:
<h:outputLink value="#{doc.value}" style="color:blue">#{doc.key}</h:outputLink>
该值为URL www.example.com.当我单击该值时,在地址栏中看到的URL是http://localhost:8080/Project/www.example.com
.为什么上下文路径以URL为前缀?
The value is a URL www.example.com. When I click on the value, the URL I am seeing in the address bar is http://localhost:8080/Project/www.example.com
. Why is the context path being prefixed to the URL?
我查找了生成的HTML,但是值是没有上下文路径的实际URL.我在JSF中尝试了<a>
,但是没有区别.
I looked up the HTML generated, but the value is the actual URL without the context path. I tried <a>
in the JSF, but there's no difference.
任何解决此问题的帮助将不胜感激.谢谢!
Any help to fix this would be appreciated. Thanks!
推荐答案
<h:outputLink />
如果值字段是相对路径,则将其值附加到当前父路径(不是Servlet上下文).这意味着,如果您在http://localhost:8080/Project/users.xhtml
中有此特定链接:
<h:outputLink />
appends its value to the current parent path (not the Servlet Context) if the value field is a relative path. It means that if you have this specific link in http://localhost:8080/Project/users.xhtml
:
<h:outputLink value="sales.xhtml">
Sales
</h:outputLink>
这将尝试将您重定向到http://localhost:8080/Project/sales.xhtml
.
This will try to redirect you to http://localhost:8080/Project/sales.xhtml
.
好吧,当您指定一个相对的地址时,JSF理解它必须将其附加到当前的父URL中.为了避免这种情况,请编写绝对网址:
Well, as you're specifying a relative one, JSF understands it must append it to your current parent url. In order to avoid that, write the absolute url:
public String getValue(){
return "http://www.example.com";
}
<h:outputLink value="#{doc.value}">
Custom external url
</h:outputLink>
这篇关于h:outputLink将上下文路径添加到URL值的前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!