Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use spring:message tag as labels in java web application

 
Yogesh Bali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

Please guide me from start on how to use the spring message tag.. if i want to use it in my application to make it internationalized.
That would be a great help to me.

Thanks and Regards,
Yogesh
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you need to declare your message bundle :

Here, the file called messages.properties (or any other international bundle, like messages_en_GB.properties) should be in the classpath. It should hold your messages. For example:

Then using the message tag :

 
Yogesh Bali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first of all, thanks Christophe for the help. But the job is still not done. What i did is as follows :

Step 1: i first created a xml file with the name applicationContext.xml in the resources folder

Step 2 : i created a file messages.properties in the same resources folder

Step 3 : i included the following jar files in the lib folder :
commons--logging-1.1.1.jar and spring.jar
Step 4 : i did the following changes in the web.xml file :

Step 5 : i made a jsp, included the following two tags in it

and

And on execution of this application on Eclipse IDE, i receive the following exception


Please help, i am unable to move ahead from this point in my application.
 
Yogesh Bali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Christophe Verré, my application is running fine.. all the labels are getting values from messages.properties file... The mistake what i was doing was that i was not including the messages.properties file to the classpath... and now when i added it to the build, its working fine. Thanks and its a great concept to make the application internationalized..
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi yogesh

i am getting same error.
please tell me where you have placed message.properties in your build.

thanks
abhay
 
pradeep gamage
Ranch Hand
Posts: 85
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put message.properties file in to your class path then this error will be solve
 
Shahid Ansari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pradeep gamage wrote:put message.properties file in to your class path then this error will be solve


Hi, what do you mean by class path here ?
My message.properties is inside /WEB-INF and is as follows:


But when I leave the first name empty while submitting I get the following error:


reg is my commandName in the JSP form page.

Can someone please help me in this...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic