In my time, I did a lot of Struts but also a lot of other frameworks. Struts 1 was where I started and I was happy to upgrade to Struts 2 when it came along. Sure, I did my share of Spring MVC and JSF but Struts kept coming up. For those who do not know, Struts is an MVC framework that came out around 2000 (2004 if you are an Apache purist).
MVC Struts Architecture
It handles a lot of boilerplate code for you. It has a series of controllers that handle incoming requests and use actions as singletons to handle the work of the requests, the actions that the requests want performed. The model handles the business logic and the data. They are usually POJOs but you may see java beans as well. This is also where we would integrate to something like hibernate. The view handles displaying data to the user. It often uses JSP and JSTL (JSP tags) and can be integrated with modern javascript frameworks (REACT, Angular, View) but that is a bit of a different approach and we will leave it at that.
Why is this being used?
Most modern devs are likely to be in spring, python or a javascript framework (Yes, sorry I did not name your favorite lang/framework ;)). Struts2 has definitely seen a decrease but there are still faithful followers out there. Usually they fall into two camps:
Legacy - Yeah, the last guy did it and we do not have time to redo it.
Really like the features - The MVC framework is simple to grasp, fairly easy to implement, tag libs give you a dynamic way to update the frontend, supports REST and it is opensource.
Let's look at some of the reasons to use Struts2
Legacy System Maintenance
If you're working within an organization that already uses Struts 2, it may make sense to continue using it for consistency and compatibility with existing systems.
Struts 2 is still actively maintained by the Apache Software Foundation, with security patches and updates.
2. MVC Framework Simplicity
Struts 2 provides a robust and simple Model-View-Controller (MVC) framework for web applications.
Its separation of concerns (Model, View, and Controller) is well-suited for developers familiar with traditional web application architectures.
3. Customizable and Flexible
Struts 2 is highly customizable, allowing developers to configure actions, interceptors, and results in a way that suits specific project requirements.
Its plugin architecture enables easy extension of core functionalities.
4. Integration with Java Ecosystem
Struts 2 integrates well with other Java technologies, such as Spring, Hibernate, and Java EE.
If your project requires leveraging these technologies, Struts 2 can be a good fit.
5. Rich Tag Libraries
Struts 2 provides extensive tag libraries (e.g., UI tags) that simplify the creation of dynamic views in JSPs.
These tags abstract complex functionality, making it easier for developers to focus on application logic.
Struts 2 includes built-in security mechanisms like CSRF protection, input validation, and prevention against common vulnerabilities (e.g., XSS, SQL injection).
If security is a priority, Struts 2 offers a solid foundation.
7. Active Community and Documentation
Struts 2 has an active community and extensive documentation that can help developers troubleshoot issues and learn more about the framework.
Many legacy tutorials, guides, and codebases exist online for reference.
8. Support for RESTful APIs
Struts 2 can expose actions as RESTful APIs, enabling integration with modern front-end frameworks such as React, Angular, and Vue.js.
This makes Struts 2 a viable backend framework for applications with modern front-end technologies.
9. Scalability for Large Applications
Struts 2 is designed to scale for large enterprise applications with complex workflows and requirements.
Interceptors and customizable action mappings allow fine-grained control over application behavior.
10. Open Source and Free
Struts 2 is an open-source framework maintained by the Apache Software Foundation.
It is free to use and does not require licensing fees, making it an attractive option for budget-conscious projects.
10. Open Source and Free
Struts 2 is an open-source framework maintained by the Apache Software Foundation.
It is free to use and does not require licensing fees, making it an attractive option for budget-conscious projects.
The downsides
While Struts 2 has its strengths, there are situations where it might not be the best choice:
Modern Development Needs: If your project requires cutting-edge features like reactive programming, microservices architecture, or serverless deployment, modern frameworks like Spring Boot, Quarkus, or Micronaut would be better suited.
Learning Curve for New Developers: Developers unfamiliar with Struts 2 may find it harder to learn compared to more modern and widely adopted frameworks.
Community Popularity: Struts 2 is less popular compared to Spring MVC, Spring Boot, or JavaScript frameworks like Node.js for backend development, making it harder to find talent or community support.
Legacy JSP-Based Views: Struts 2 relies heavily on JSPs for its default view layer, whereas modern frameworks use more advanced templating engines or integrate natively with front-end technologies.
Some of this can be mitigated but in the end, you put a lot of work into those changes. You need to understand the scope of your project before you decide on your framework.
Conclusion
So, where are we today. Do we use Struts 2 or not? Some possible usecases:
Enterprise Applications: Struts 2 works well for large-scale enterprise applications where its modular architecture and integration capabilities shine.
Backend for Legacy Systems: If you're maintaining or extending an application originally built with Struts 2, it makes sense to continue using it.
Education and Training: Struts 2 can be a good teaching tool for understanding the basics of MVC frameworks and web application architecture.
Government or Regulated Projects: Some government or regulated industries still use Struts 2 due to its stability and long-term support.
It is not going to be right for all projects and to be clear, it is, as with all architecture, a calculation of tradeoffs. Spring is much more flexible, performant and generally better supported.
I still enjoy seeing the telltale '.do' suffix on a web url.
I used Struts extensively before fully embracing Spring. In the middle I did have a brief run with JSF. I'm curious to hear your take on JSF.