h:outputLink prefixes context path to a URL value

↘锁芯ラ 提交于 2020-01-06 06:50:10

问题


I have a h:outputLink as shown below:

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

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?

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!


回答1:


<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>

This will try to redirect you to http://localhost:8080/Project/sales.xhtml.

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>


来源:https://stackoverflow.com/questions/22699352/houtputlink-prefixes-context-path-to-a-url-value

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