有没有更好的东西来生成绝对链接?
在 JSF 2.0 中生成绝对链接的更好方法是什么?现在我正在以丑陋的方式使用
和 #{facesContext.externalContext.requestContextPath}
,如下所示。我不想使用 JSTL 和
<h:outputLink value="#{facesContext.externalContext.requestContextPath}/pages/home.jsf">Home</h:outputLink>
Is a better way to generate absolute links in JSF 2.0 ? Right now I'm using <h:outputLink/>
in that ugly way with #{facesContext.externalContext.requestContextPath}
like below. I don't want to use JSTL and <c:url />
<h:outputLink value="#{facesContext.externalContext.requestContextPath}/pages/home.jsf">Home</h:outputLink>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
#{facesContext.externalContext.requestContextPath}
缩短为#{request.contextPath}
。您甚至可以摆脱它以使用 HTML改为
标记。在这种特殊情况下,更好的是使用
代替。它可以在outcome
属性中采用上下文相关的导航案例路径:JSF 将在生成
时负责添加正确的上下文路径和
元素:FacesServlet
映射;另请参阅:
You can shorten
#{facesContext.externalContext.requestContextPath}
to#{request.contextPath}
. You can even get rid of it to use HTML<base>
tag instead.In this particular case, better is to use
<h:link>
instead. It can take a context-relative navigation case path inoutcome
attribute:JSF will take care about adding the right context path and
FacesServlet
mapping while generating the<a>
element:See also: