Javatpoint Logo
Javatpoint Logo

Struts2 String Length Validation Example

The stringlength validator specifies that string must be of given length. It can be used in username, password etc.

It trims the string bydefault then checks if its length is of the given length.

Parameters of stringlength validator

There are 4 parameters defined for stringlength validator.

fieldNamespecifies the field name that is to be validated. It is required in Plain-Validator only.
minLength specifies the minimum length. It is ignored bydefault.
maxLength specifies the maximum length. It is ignored bydefault.
trimtrims the field values. It is bydefault true means it is enabled bydefault.

Example of stringlength validator

Full example of stringlength validator

1) Create index.jsp for input

This jsp page creates a form using struts UI tags. It receives name, password and email id from the user.


2) Create the action class

This action class inherits the ActionSupport class and overrides the execute method.

3) Create the validation file

Here, we are using bundled validators to perform the validation.


4) Create struts.xml

This xml file defines an extra result by the name input, and an interceptor jsonValidatorWorkflowStack.


5) Create view component

It is the simple jsp file displaying the information of the user.


Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA