Java 在jsp中使用spring:eval显示属性值

Java 在jsp中使用spring:eval显示属性值,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我正在寻找在jsp文件中显示Spring属性值的帮助 我发现了一个链接,它与我的要求相同。 点击 我正在使用Spring 2.5 这是我的applicationContext-util.xml文件: xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context" http://www.springframework.org/s

我正在寻找在jsp文件中显示Spring属性值的帮助

我发现了一个链接,它与我的要求相同。 点击

我正在使用Spring 2.5

这是我的applicationContext-util.xml文件:

xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd

<util:properties id="viewPropertyConfigurer" location="classpath:conf/app_config.properties"/>
<context:property-placeholder properties-ref="viewPropertyConfigurer" />
在我的应用程序中,我也在使用servlet过滤器,希望这不会成为一个问题


提前感谢您的帮助。

据我所知,
EvalTag
是在Spring3中添加的(
@自3.0.1以来)。如果您使用的是Spring2.5,那么您没有
支持

可能的解决办法:

  • 切换到弹簧3+
  • 使用自定义处理程序拦截器向请求中添加其他信息
  • 编写自己的标记以从应用程序上下文中提取信息

更新(选项2示例):


然后,您需要在处理程序映射中配置此拦截器。

请共享配置文件感谢nidhin、Pavel Horal提供的宝贵信息。我用Spring3+创建了示例项目,它运行良好。我的项目是2.5+版本,现在如果我切换到3.0,那么它需要更改一些包,并需要测试整个应用程序。正如Pavel Horal所说,创建标记并获取属性值,我可以看到有两个选项可以实现它。我通过java加载属性。二,。从Spring注入的属性文件中获取属性值。继续..我想使用第二个选项,因为我不想在两个地方给出文件名,我检查了PropertyResourceConfigurator api,无法根据键获取值。不管怎样,我可以通过编程方式获取数值。如果我遗漏了什么,请告诉我。很抱歉打扰大家。我得到了如何从PropertyResourceConfigurator获取值的链接。下面是您可以加载两次属性的示例—一次用于
PropertyPlaceHolderConfigure
,一次在自定义处理程序拦截器中加载。我用一个例子更新了我的答案。嗯。。。我可能读错了你的评论。您要使用自定义标记解决方案吗?
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<spring:eval expression="@viewPropertyConfigurer.getProperty('role.admin')" />
[ERROR,context.JspTilesRequestContext,http-8080-1] -[UID=galips - SessionID=691A896E807850568DF9B0F5356F6CB2] - JSPException while including path '/WEB-INF/jsp/menu.jsp'.
public class CommonViewAttributesInterceptor extends HandlerInterceptorAdapter {

    private static final String PROPERTIES_ATTR = "properties";

    private Properties properties = new Properties();

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response,
            Object handler, ModelAndView modelAndView) throws Exception {
        request.setAttribute(PROPERTIES_ATTR, properties);
    }

    public void setPropertiesSource(Resource resource) throws IOException {
        InputStream input = resource.getInputStream();
        try {
            properties.load(input);
        } finally {
            input.close();
        }
    }

}