Using property file value in jsp

Sometimes we need to use property file value directly into a JSP without using on the fly request to get the data. To achieve this we are going to use spring:eval and some spring beans.

Usage:

  • Add following line in your spring configuration file.
<util:properties id="propertyConfigurer" location="classpath:yourPropertyFileClasspathHere" />
<context:property-placeholder properties-ref="propertyConfigurer" />
  • Add this at the top of the JSP
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
  • Use eval to get the value in JSP:
<spring:eval expression="@propertyConfigurer.getProperty('propertyNameHere')" />

Above value can be used anywhere in jsp just like normal EL to provide you the value required.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s