What Is New in Apache Struts 2.0
Struts 2.0 is a major overhaul, moving from the classic Struts 1.x codebase to a new foundation built on WebWork 2. This release introduces a new architecture, streamlined configuration, and a powerful expression language.
| Category | Key Changes |
|---|---|
| New Features | WebWork 2 foundation, Interceptors, Improved Tag APIs, AJAX themes |
| Architecture | Dependency Injection, Enhanced Expression Language (OGNL) |
| Configuration | Annotation support, Zero-configuration defaults |
| Deprecated | Struts 1.x APIs and Tiles support |
How did the framework architecture change?
The core architecture shifted from Struts 1 to WebWork 2. This means the entire request lifecycle is now managed by a filter, FilterDispatcher, instead of a servlet.
Interceptors are the new backbone, handling common tasks like validation and workflow before your action executes. This is a cleaner separation of concerns compared to the monolithic request processor in Struts 1.
What are the new configuration options?
Configuration got a major simplification. You can now use Java 5 annotations directly on your action classes to define results and mappings, moving away from massive XML files.
The framework also provides sensible defaults through "convention over configuration." If you name your JSPs to match your action names, you often don't need any XML configuration at all.
What improvements were made to the expression language?
Object-Graph Navigation Language (OGNL) is now the default expression language throughout the framework. It's far more powerful than what was available in Struts 1, allowing for complex data manipulation directly in your JSPs and configuration.
In practice, this means your UI tags can reference and update your action's properties and methods much more effectively, reducing the need for scriptlet code.
What happened to Tiles and other Struts 1 features?
Traditional Struts 1 APIs and the built-in Tiles support are deprecated. The recommendation is to migrate to the standalone Tiles project or alternative templating solutions like SiteMesh.
This change matters because it signals a clean break from the past. You're encouraged to build new applications using the new WebWork-based patterns rather than trying to port old Struts 1 code directly.
FAQ
Is Struts 2.0 a direct upgrade from Struts 1.x?
No, it's a completely different framework built on WebWork 2. Migrating requires rewriting actions and reworking configuration, as it's not backward compatible.
Do I have to use annotations for configuration now?
No, annotations are optional. You can still use XML configuration (struts.xml), but annotations offer a more streamlined approach for many use cases.
What is the main advantage of using interceptors?
Interceptors allow you to apply cross-cutting concerns like logging, security, or validation declaratively. This keeps your action code clean and focused on business logic.
Can I use my existing Struts 1 tags with Struts 2.0?
No, the old tags are not compatible. You must use the new Struts 2 tag library, which is more powerful and integrates with OGNL.
What replaces the Tiles framework for layout management?
The built-in Tiles support is deprecated. For new projects, you should use the standalone Apache Tiles project or integrate a different templating technology like SiteMesh.