outputLink和graphicImage之间的EL上下文路径评估差异 [英] EL context path evaluation difference between outputLink and graphicImage

查看:103
本文介绍了outputLink和graphicImage之间的EL上下文路径评估差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下内容在我们的应用程序中获取帮助文档.我的问题是,尽管<h:graphicImage>正确评估了上下文路径,但h:outputLink却没有将其评估为零.我试过在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.

两个EL表达式的计算方式有什么区别?

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>

推荐答案

上下文路径未出现在

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.

该上下文路径出现在 <h:graphicImage> 是完全可以预期的.这是组件本身自动包含的.实际上,整个表达式是多余的,下面的表达式应该可以很好地工作.

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"/>

<h:outputLink>确实不会自动包含上下文路径.只有 <h:link> 可以做到这一点.您需要自己添加它.在Facelets中,可以使用#{request}获取 HttpServletRequest 依次具有 getContextPath() (并且<h:graphicImage>在幕后使用).

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">

这篇关于outputLink和graphicImage之间的EL上下文路径评估差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆