Sitemap
Imran Khan

Imran Khan

Tech Enthusiast

Struts2 ActionSupport addActionError

2 min readFeb 7, 2023

ActionSupport class implements many interfaces such as Action, Validateable and Serializable etc.

Here we will be using ActionSupport class to apply validation in action class.

Note: Before working on ActionSupport class to show field errors, please create Struts project using this Link.

Follow below steps once project setup is done and started working in local Eclipse.

  1. Open UserAction.java class and extends ActionSupport class. override the vaildate() method to handle validation errors and messages.

In this example we are going to use addActionError which will be responsible to an action error.

Press enter or click to view image in full size

2. Update struts.xml file with below content to handle error and add below highlighted line red in color.

Press enter or click to view image in full size

3. Update index.jsp with below content to take name and password as an input.

4. Update user.jsp to show name and password enter on index.jsp page

5. Run application and load below page:

Get Imran Khan’s stories in your inbox

Join Medium for free to get updates from this writer.

http://localhost:8081/struts-demo

Press enter or click to view image in full size

Do not enter name and password having length less than 4 will given below error

Press enter or click to view image in full size

Provide name and password length greater than 4 will redirect to user.jsp page and print entered value on index.jsp page.

I hope you found out this article interesting and informative. Please share it with your friends to spread the knowledge.

You can follow me for upcoming blogs follow.
Thank you!

--

--