gpt4 book ai didi

java - 使用 Spring :eval display property value in jsp

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:29:05 25 4
gpt4 key购买 nike

我正在寻求有关在 jsp 文件中显示 Spring 属性值的帮助。

我找到了一个与我有相同要求的链接。点击Using spring:eval inside hasRole

我正在使用 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" />

在我的 menu.jsp 中

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<spring:eval expression="@viewPropertyConfigurer.getProperty('role.admin')" />

在 lib 文件夹中,我还有 spring-web-2.5.6.jar 文件,以确保 eval 在 jsp 中正常工作。但是不确定一旦我添加了 spring:eval 标签,jsp 根本没有加载它抛出的问题是什么

[ERROR,context.JspTilesRequestContext,http-8080-1] -[UID=galips - SessionID=691A896E807850568DF9B0F5356F6CB2] - JSPException while including path '/WEB-INF/jsp/menu.jsp'.

在我的应用程序中,我也使用了 servlet 过滤器,希望这不会成为问题。

提前感谢您的帮助。

最佳答案

据我所知EvalTag在 Spring 3 ( @since 3.0.1 ) 中添加。如果您使用的是 Spring 2.5,那么您没有 <spring:eval>支持。

可能的解决方案:

  • 切换到 Spring 3+
  • 使用自定义处理程序拦截器向您的请求添加额外信息
  • 编写您自己的标签以从应用程序上下文中提取信息

更新(选项 2 示例):

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();
}
}

}

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

关于java - 使用 Spring :eval display property value in jsp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16971565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com