Struts 2 loading error messages from resource bundle

            In this tutorial we'll explore using Struts 2 message resource capabilities (also called resource bundles) to use it with validation.

Configure your properties file in file


Now create a new properties file to keep your error messages

uname.vali = User Name is required.
pass.vali = Password is required.
error.vali = User Name or Password is incorrect.

In validate function use getText("key") to get the value from file

public void validate() {
        if (getUname().length() == 0) {
            addFieldError("uname", getText("uname.vali"));
        if (getPass().length() == 0) {
            addFieldError("pass", getText("pass.vali"));
        else if (!getUname().equals("veera") && !getPass().equals("pass")) {





            Struts 2 resource bundle validation war

            Struts 2 resource bundle validation maven zip

Related Post