有没有更好的东西来生成绝对链接?

发布于 2024-12-13 15:11:23 字数 349 浏览 1 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

客…行舟 2024-12-20 15:11:23

您可以将 #{facesContext.externalContext.requestContextPath} 缩短为 #{request.contextPath}。您甚至可以摆脱它以使用 HTML改为 标记

在这种特殊情况下,更好的是使用 代替。它可以在 outcome 属性中采用上下文相关的导航案例路径:

<h:link value="Home" outcome="pages/home" />

JSF 将在生成 时负责添加正确的上下文路径和 FacesServlet 映射; 元素:

<a href="/contextname/pages/home.jsf">Home</a>

另请参阅:

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 in outcome attribute:

<h:link value="Home" outcome="pages/home" />

JSF will take care about adding the right context path and FacesServlet mapping while generating the <a> element:

<a href="/contextname/pages/home.jsf">Home</a>

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文