What is the Difference Between Struts and Struts2?

🆚 Go to Comparative Table 🆚

The main differences between Struts 1 and Struts 2 are:

  1. Front Controller: In Struts 1, the front controller is a servlet called ActionServlet, while in Struts 2, it is a filter called FilterDispatcher.
  2. Action Classes: In Struts 1, action classes must extend the Action class or DispatchAction class, and the execute method should return an ActionForward object. In Struts 2, action classes can be created by implementing the Action interface, extending the ActionSupport class, or by a simple POJO class with an execute() method.
  3. Thread Safety: Struts 1 action classes are singleton and not thread-safe, meaning only one instance of a class is used to handle all requests to an action. In Struts 2, action objects are instantiated for every request, eliminating thread-safety issues.
  4. Interceptor Stacks: Struts 1 supports separate Request Processors (lifecycles) for each module, but all actions in the module must share the same lifecycle. Struts 2 supports creating different lifecycles on a per-action basis via Interceptor Stacks.
  5. Type Conversion: Struts 1 properties in ActionForm are almost in String form, with per-class convertors that are not configurable. Struts 2 uses Object Graph Navigation Language (OGNL) for type conversion.
  6. Configuration File: The configuration file used in Struts 1 is struts-config.xml (or any other name) and is placed in the WEB-INF folder. In Struts 2, the configuration file is named struts.xml and is placed inside WEB-INF/classes. Multiple configuration files can also be used.
  7. Expression Language: Struts 1 uses BeanShell as its expression language, while Struts 2 uses OGNL and can also use Java Standard Tag Library (JSTL).
  8. Servlet Dependency: Struts 2 does not depend on the Servlet API, unlike Struts 1.

These differences make Struts 2 a more flexible and powerful framework compared to Struts 1.

Comparative Table: Struts vs Struts2

Here is a table comparing the differences between Struts 1 and Struts 2:

Feature Struts 1 Struts 2
Action Classes Extends abstract base class Implements Action interface and supports Interceptor Stacks
Lifecycle Management Supports separate Request Processors for each module Supports separate lifecycles on a per Action basis
Expression Language Integrates with JSTL, uses JSTL EL Supports JSTL EL and a more powerful expression language
Object Binding Binds objects into the page context using JSP mechanism Uses ValueStack technology to make values accessible to taglibs
Type Conversion ActionForm properties are almost in the form of Strings Supports type conversion with configurable converters

Struts 2 is a more powerful framework compared to Struts 1, with improvements in action classes, lifecycle management, expression language, object binding, and type conversion.