• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Load a properties file in application context

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am pretty new to Spring MVC. my problem goes as below.
i am using conventional directory strucure i.e. separate folder for properties,css,js under WEB-INF.
i have my servletname-servlet.xml and applicationContext.xml under WEB-INF

I have a home page where i show several links, which are stored in a properties file. this is loaded as below from my *-servlet.xml



this will load all the properties from startup.properties in servlet context, if my understanding is right...

in my controller i do get all the links from 'startup.properties', pull a particular link using EL and @Value annotation, store it in session and then display on my home page...works fine...but this involves a lot of tasks like pulling tht particular link from the servlet-context and storing in the session.

for eg. i store the page header in this property file,i retrieve it as



then i store it in my session and then display on my header using EL...

do i have to do this always? would loading the startup.properties in applicationContext.xml do the trick of making it available to JSP directly? [ BTW , i tried this , but doesn't even retrieve in any of my controllers when @Value is used with EL as above]

Is there a way that i load the property file in application context rather than servlet context and display a particular property directly on a JSP using EL??

i hope i am clear enough...i don't want to meddle with session or anything...just configure my property file like above in say applicationContext and use EL to display a property on the JSP....

thanks in advance for the help.

PS -- even properties loaded in *-servlet.xml can't be displayed directly on a JSP...is there a way to do that either ??
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are actually are looking for is ResourceBundleMessageSource see the reference documentation for it here:
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#context-functionality-messagesource

To access it in the JSP use the Spring message tag. See the reference documentation here:
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/spring.tld.html#spring.tld.message


Simple example below:




In your messages.properties file



And access it in your JSP using the Message tag.
 
Pranav Nakate
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a ton Bill...!!!

That was real help...

PS -- i just tried this ...giving me following error...



my applicationContext.xml has below code --



the applicationContext.xml is directly below WEB-INF and the 'pageResources.properties' that is configured above is in 'properties' folder which is directly under 'WebContent' in my eclipse....

how do i get rid of the exception???
 
Pranav Nakate
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved the problem of the exception :: configured 'ReloadableResourceBundleMessageSource' instead of 'ResourceBundleMessageSource' in applicationContext.xml, as given in the link in Bill's post!



 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic