1

I have a pageSize variable configured in spring properties. I need to access this pageSize property in almost all the jsps. What is the best way to get hold of this spring property.

src\main\resources\web.properties contains default.page.items.size=10

  <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
    <property name="locations">
      <list>
        <value>classpath:web.properties</value>
        <value>classpath:core.properties</value>
      </list>
    </property>
  </bean>

I know how to access the property in the controller but as this property is been accessed my mutliple pages hence i want some way to access it javascript or jsp directly

4

1 Answer 1

1

I used this in a old project (not sure if still works) in your dispatcher context declare a bean like:

<bean id="myProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
               <list>
                     <value>classpath:web.properties</value>
                     <value>classpath:core.properties</value>
                </list>
         </property>
</bean>

and then, if using standard JSTL view resolver:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="order" value="2"></property>
          <property name="viewClass"
                  value="org.springframework.web.servlet.view.JstlView" />
          <property name="prefix" value="/WEB-INF/jsp/" />
          <property name="suffix" value=".jsp" />
          <property name="exposedContextBeanNames">
               <list>
                     <value>myProps</value>
               </list>
          </property>
</bean>

You should be able to access the properties inside JSP using ${myProps.XXX}

1
  • The above solution didnt work for me as I am using UrlBasedViewResolver
    – nagendra
    Jan 10, 2014 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.