Get all updates of Java4s
Follow Us: Email Newsletter

How To Use Resource Bundle In Struts2

Struts »on Oct 23, 2011 { 5 Comments } By Sivateja

In struts2, if we want to get labels and error messages from an external file then we need to use resource bundle.  The resource bundle in struts 2 is similar to struts 1 but the difference is,  in struts 1 we need to configure the resource bundle name in struts-config.xml, but in 2.x we need to configure our bundle name in file.

Both our Bundle, and files need to be store in classes folder only

Syntax of

struts.custom.i18n.resources= your bundle name


(Let my bundle name being java4s)

Syntax of

enter.user   =  User name
enter.pass   =  Password
user.wrong =  You must enter the user
pass.wrong =  Password should be entered
u.p.wrong   =  User or Password is wrong

something like key = value

In action class if any logic is failed then also we get error messages from a bundel.  At this time we need to make it as an actionError, not fieldError.  If we want to display an action error on a browser then in jsp we need to use the tag called <s:actionerror>

We will see this in the next example with programmatic validations



You Might Also Like

  ♦ About Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


5 Responses to “How To Use Resource Bundle In Struts2”
  1. Mohammed Vaseem says:

    Hello Java4s,
    How to use an application with multiple .properties file?
    When I tried to have it, Struts is considering only the first file which i specified in file.
    Please help
    Thanks in Advance
    Mohammed Vaseem

  2. Java4s says:


    We can write multiple resource bundles specified by providing a comma, some thing like..

    struts.custom.i18n.resources=java4s,java4s2,java4s3…..bla bla

    Hope you will clear.

  3. Kranthi says:

    Hi Java4s,

    I have a requirement to display country related states in the drop-down list of Struts2 tags with out using AJAX/JQuery client side code.
    By using struts 2 tags with out refreshing the whole page we need to display cities drop-down list.

    Please help me in solving the above requirement.

    Thanks in Advance
    Kranthi Kumar

  4. viren shah says:

    Hello sir,
    why we use the resource bundle in struts2 and whats the main role of interceptor and difference between action and interceptor


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful LinksCurrent & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2017 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.