EL上下文路径评估outputLink和graphicImage之间的差异

发布于 2024-10-01 19:25:04 字数 510 浏览 1 评论 0原文

我正在使用以下内容在我们的应用程序中获取帮助文档。我的问题是,虽然 正确评估上下文路径,但 h:outputLink 将其评估为空。我尝试在 h:outputLink 中使用 $# 因为我知道它们有不同的评估时间。

这两个 EL 表达式的计算方式有何不同?

<h:outputLink value="${pageContext.servletContext.contextPath}/services/help.pdf">
    <h:graphicImage 
        url="${pageContext.servletContext.contextPath}/images/help.png" 
        alt="Online Help"/>
</h:outputLink>

I'm using the following to get a help document in our app. My problem is that while the <h:graphicImage> evaluates the context path correctly, the h:outputLink evalutates it to nothing. I have tried using both $ and # in the h:outputLink because I understand they have different evaluation times.

What is the difference in how the two EL expressions evaluate?

<h:outputLink value="${pageContext.servletContext.contextPath}/services/help.pdf">
    <h:graphicImage 
        url="${pageContext.servletContext.contextPath}/images/help.png" 
        alt="Online Help"/>
</h:outputLink>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

转身泪倾城 2024-10-08 19:25:04

上下文路径不会出现在 < 中h:outputLink> 表明您实际上正在使用 Facelets 而不是 JSP。 Facelets 中根本不存在 ${pageContext}。它特定于旧版 JSP。两个表达式的计算结果均为空字符串。因此,它们之间根本没有区别。

上下文路径出现在 中;完全符合预期。这是组件本身自动包含的。事实上,整个表达式是多余的,下面的应该也可以。

<h:graphicImage url="/images/help.png" alt="Online Help"/>

确实不会自动包含上下文路径。仅 就是这样做的。您需要自己将其包括在内。在 Facelets 中,您可以使用 #{request} 获取 HttpServletRequest 又具有 getContextPath() 以及(由 在幕后使用)。

<h:outputLink value="#{request.contextPath}/services/help.pdf">

That the context path doesn't appear in <h:outputLink> suggests that you're actually using Facelets instead of JSP. The ${pageContext} doesn't exist in Facelets at all. It's specific to legacy JSP. Both expressions have just evaluated to an empty string. There is thus no difference between them at all.

That the context path appears in <h:graphicImage> is fully expected. This is automatically included by the component itself. In fact, the entire expression is superfluous and the following should work as good.

<h:graphicImage url="/images/help.png" alt="Online Help"/>

The <h:outputLink> does indeed not automatically include the context path. Only the <h:link> does that. You'd need to include it yourself. In Facelets, you can use #{request} to get a handle to HttpServletRequest which in turn has a getContextPath() as well (and which is used by <h:graphicImage> under the covers).

<h:outputLink value="#{request.contextPath}/services/help.pdf">
毁梦 2024-10-08 19:25:04

试试这个 #{facesContext.externalContext.requestContextPath} 我希望这可以帮助您也检查此链接 链接文本

问候,
塞尔吉奥·瓦尔迪兹

Try this #{facesContext.externalContext.requestContextPath} i hope this can help you also check this link link text

Regards,
Sergio Valdez

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