Announcement Announcement Module
Collapse
No announcement yet.
Read the Properties values in JSP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Read the Properties values in JSP

    I am running a java web application on Java 6 and Spring 3.0.

    I have properties file used by the web application and is loaded by the spring framework on server start.

    config.properties
    url=http://www.url.com
    test.url=http://www.test.com
    dev.url=http://www.dev.com
    I have requirement to use the properties values in java and jsp code. I am able to access the value in java using annotations provided in spring 3.0 : @Value("${test.url}")

    To use the properties in JSP, I am trying to load the properties into servlet context, so that the properties can be referenced in the JSP directly

    servletContext.setAttribute("props", properties);

    In my jsp, when i print ${props}, it results the following ...

    {url=http://www.url.com,test.url=http://www.test.com,dev.url=http://www.dev.com}

    But when i print ${props.test.url}, it prints nothing (the same works for ${props.url}).

    Is this an issue or am i doing something wrong. How can i get the ${props.test.url} work in jsp

  • #2
    Put it in quotes

    The problem is EL first tries to look for a property called "test" on props, which is a map, so it fails resolve.
    If it found a property called 'test', it would then try and resolve a property called 'url' on that object.
    It can't interpret 'test.url' on its own.

    Try:

    ${props['test.url']}
    Last edited by nostradamus; May 24th, 2012, 02:29 AM.

    Comment


    • #3
      How do we get access to the properties map in JSPs rendered by the web flow?
      The properties map always seems to be null.
      (It's not null if the JSP is rendered using traditional spring MVC)

      Comment

      Working...
      X