View Poll Results: Should this feature be added to Spring 3.0.x?

Voters
0. You may not vote on this poll
  • Yes.

    0 0%
  • No. This feature already exists in Spring 3.0.x.

    0 0%
Results 1 to 5 of 5

Thread: How can I directly access util:properties in JSP?

  1. #1
    Join Date
    Aug 2010
    Posts
    5

    Post How can I directly access util:properties in JSP?

    I have defined in applicationContext.xml

    HTML Code:
    <util:properties id="myProperties" location="classpath:myProps.properties"></util:properties>
    I'd now like to directly access the properties loaded in a JSP.
    Note: I don't want them to be set using @Value in a DTO/Form.

    For Ex., in my JSP I'll write

    HTML Code:
    <a href="${myProperties['WEB_CLIENT_URL']}" target="_blank">test
    </a>
    The problem is the property value is not shown in the JSP because it is not accessible. Am I missing something here?

    I saw another blog

    http://j2eecookbook.blogspot.com/200...ia-spring.html

    Since that blog was written in 2007, I expected this feature to be in Spring 3.0.x.

  2. #2
    Join Date
    Jun 2012
    Posts
    7

    Default

    Were you able to resolve this? I need to read properties in my jsp and looking for a solution.

  3. #3
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Right solution is of course to use mvc principles. Inject the properties in variables of your controller using the @Value annotation, then in the @RequestMapping methods use those variables to populate the model. In jsp, access the model using standard jstl.

  4. #4
    Join Date
    Jun 2012
    Posts
    7

    Default

    Thanks. But this just is a traditional jsp with no Action class like a header.jsp and also I am using Spring 2.5.6.

  5. #5
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    You're using Spring but no mvc framework? I strongly suggest using at least basic Spring mvc controllers!
    Anyway, you can still populate the model "the old way" by calling request.setAttribute() or adding "?param=value" to the request url...and, Spring 2.5 has no support yet for the @Value annotation but you still can define the bean in xml and inject values using placeholders.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •