Programming Thoughts
Struts 2 - Annotation-based Validation
Fails Out-of-the-Box Example
A Struts 2 feature conflicts with others
Struts 2 is a popular MVC framework for Java-based web applications. As Java evolved and supported new language features over the years, Struts evolved to utilise them. In particular, Struts used the annotations feature, in-code configuration that eliminates separate, arcane configuration files. Alas, annotation-based form validation doesn't work out-of-the-box. This article describes a working example.
Live example
A demonstration application can be accessed here. It uses the default interceptor stack, not the interceptors described in later articles. The start page looks like the following. Enter empty or junk values to test form validation.

Figure 1: Starting page
Download
Source code of the demonstration application can be downloaded here as zip files. They require the following.
- JDK 8 or better
- Maven 3
- Jakarta EE server, such as Tomcat 9
Extract the Example 7 files and run mvn
, which compiles into example7.war. Copy that into your
Jakarta server and run the /example7
URL.
Next part
Continued in Validation Design is Too Fragile.