What is the Difference Between Struts and Struts2?
🆚 Go to Comparative Table 🆚The main differences between Struts 1 and Struts 2 are:
- Front Controller: In Struts 1, the front controller is a servlet called ActionServlet, while in Struts 2, it is a filter called FilterDispatcher.
- 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.
- 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.
- 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.
- 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.
- 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.
- Expression Language: Struts 1 uses BeanShell as its expression language, while Struts 2 uses OGNL and can also use Java Standard Tag Library (JSTL).
- 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.
Read more:
- Struts vs Spring MVC
- Strut vs Column
- Shocks vs Struts
- Leapster vs Leapster 2
- iPad vs iPad 2
- RSS vs RSS2
- Apple iPad vs Apple iPad 2
- Android 2.2.1 vs Android 2.2.2
- SaaS vs SaaS 2
- Motorola Droid X2 vs Droid 2
- Apple iPad Air vs iPad Air 2
- Android 2.2.2 vs Android 2.3.4
- Android 2.3 vs Android 2.4
- Motorola Droid X vs Droid 2
- JSF2 vs Seam3
- Samsung Galaxy S vs Galaxy S2
- MacBook Air vs iPad 2
- Android 2.2 vs Android 2.3.3
- SATA vs SATA II