EL上下文路径评估outputLink和graphicImage之间的差异
我正在使用以下内容在我们的应用程序中获取帮助文档。我的问题是,虽然
正确评估上下文路径,但 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上下文路径不会出现在
< 中h:outputLink>
表明您实际上正在使用 Facelets 而不是 JSP。 Facelets 中根本不存在${pageContext}
。它特定于旧版 JSP。两个表达式的计算结果均为空字符串。因此,它们之间根本没有区别。上下文路径出现在
中;
完全符合预期。这是组件本身自动包含的。事实上,整个表达式是多余的,下面的应该也可以。
确实不会自动包含上下文路径。仅
就是这样做的。您需要自己将其包括在内。在 Facelets 中,您可以使用#{request}
获取HttpServletRequest
又具有getContextPath()
以及(由
在幕后使用)。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.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 toHttpServletRequest
which in turn has agetContextPath()
as well (and which is used by<h:graphicImage>
under the covers).试试这个 #{facesContext.externalContext.requestContextPath} 我希望这可以帮助您也检查此链接 链接文本
问候,
塞尔吉奥·瓦尔迪兹
Try this #{facesContext.externalContext.requestContextPath} i hope this can help you also check this link link text
Regards,
Sergio Valdez