Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using spring:eval display property value in jsp

I am looking for help to display the Spring property value in a jsp file.

I found one link which is having the same requirement of mine. Click Using spring:eval inside hasRole

I am using Spring 2.5

This is my applicationContext-util.xml file:

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

in my menu.jsp

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

in lib folder I also have spring-web-2.5.6.jar file to make sure the eval should work fine in jsp. But not sure what is the issue once i add spring:eval tag the jsp is not at all loading it throws

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

In my application I am using servlet filter as well hope it will not be an issue.

Thanks for your help in advance.

like image 285
sats Avatar asked Sep 02 '26 04:09

sats


1 Answers

As far as I know EvalTag was added in Spring 3 (@since 3.0.1). If you are using Spring 2.5, then you don't have <spring:eval> support.

Possible solutions:

  • switch to Spring 3+
  • use a custom handler interceptor to add additional information to your request
  • write your own tag to pull up information from application context

Update (option 2 example):

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

}

Then you need to configure this interceptor within your handler mapping.

like image 57
Pavel Horal Avatar answered Sep 03 '26 20:09

Pavel Horal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!