Olivier.Roger
Olivier.Roger

Reputation: 4249

Tomcat - Access properties from JSP

I am using Spring. A properties placeholder is used to access all properties in the application. I would like to use it also in JSP pages.

I found some solutions using Spring-MVC but I do not use it. I uses a org.apache.jasper.servlet.JspServlet that I could overwrite in my web.xml if necessary.

Is it possible to somehow expose the properties to the JSP code without having to overwrite the ServletContextListener class ? (like it was done in this article)

Upvotes: 2

Views: 2115

Answers (1)

NimChimpsky
NimChimpsky

Reputation: 47290

Inject the property into your controller/servlet, then add that value to your model. Access that attribute as you would any other :

@Value("${myProperty.setting}")
private String whateverYouWantToCallIt;

then :

model.addAttribute("mySetting", whateverYouWantToCallIt);

and in JSP :

<span>${mySetting}</span>

And if its just a text message used in lots of places you could use message.properties.

Upvotes: 3

Related Questions