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