This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with getting Message from properties file in Controller, but works in JSP

 
ashish kulkarni
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting below error in my Controller class when trying to get message from resource file, but i am able to get the same message in jsp file

my properties file is messages.properties and not messages_en_US.properties , this might be issue, but i want to make it work using messages.properties because i cannot change the file name to messages_en_US as it might broke my other part of web application

this is my set up,
in servlet-contxt.xml file

in my controller this is what i do use AutoWired to load the bean



This is how i do in JSP file and it works fine


my properties file is as below



This is the error message
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you try spring:message

http://static.springsource.org/spring/docs/2.5.x/reference/spring.tld.html#spring.tld.message
 
ashish kulkarni
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getting messages from properties file works fine in JSP, but not in controller
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry!!

Can you try:-

msgSrc.getMessage("label.firstname", null, null);
 
ashish kulkarni
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
msgSrc.getMessage("label.firstname", null, null);

This also does not work

I get below error


org.springframework.context.NoSuchMessageException: No message found under code 'label.firstname' for locale 'null'.
org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:135)
com.tauck.spring.HomeController.home(HomeController.java:40)

 
ashish kulkarni
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it working by changing servlet-contxt.xml file

From



To

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic