Announcement Announcement Module
Collapse
No announcement yet.
JSP Web App configuration the Spring way? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSP Web App configuration the Spring way?

    Simple question, but I haven't been able to find a simple answer:

    I'm using Spring, JSP 2.0 and JSTL

    I want to have a configuration parameter for my web application. It will be deployed on various intranets, with different requirements.

    Something like:
    Code:
    # app.properties
    # Can users foo?
    foo.enabled=false
    I guess this should go in a properties file, or conceivably it could be in the *-servlet.xml as a bean.

    Then I want a JSP that has something like this:
    Code:
    <%-- Only display the link if foo is enabled --%>
    <c:if test="${...foo.enabled='true'}">
    <a href="...">Foo</a>
    </c:if>
    It seems like I want to use EL to access an application property. What is the best way to do this?
    Last edited by jawheeler; Sep 3rd, 2008, 12:50 PM. Reason: Added code tags per Marten's request

  • #2
    Please use [ code][/code ] tags when posting code....

    I would create some configuration object in your applicationContext which holds the properties. Then create a HandlerInterceptor which always adds that configuration object to the request attributes so that it is accessible in the jsp.

    Code:
    public class ConfigurationAddingHandlerInterceptor extends HandlerInterceptorAdapter {
    
      private Configuration configuration;
    
      public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
        modelAndView.addObject("configuration", configuration);
      }
    
    }
    Code:
    <c:if test="${configuration.foo}">
      //something here
    </c:if>

    Comment

    Working...
    X