Struts 1 and Struts 2 Difference
This tutorial lists the difference between struts 1 and struts 2.
1. Front Controller
strut 1.x– Front controller used is a servlet called the ActionServlet
struts 2.x– A Filter called FilterDispatcher is used a the front controller.
You may check the article How Struts 2 Works to have a good understanding of the working of struts 2.
2. ActionForms
strut 1.x– ActonForms are used in Struts 1. These classes map with the jsp forms. The Action classes use the data in these ActonForms to populate Data Transfer Objects.
struts 2.x– Acton Forms are not used. The jsp form directly maps to POJO classes, and there is no need to create DTO, thereby the number of classes decreases leading to less maintenance.
3. Validation
strut 1.x– Validation can be done in validate method of the Form Bean.
struts 2.x– No Form Beans so validation code can be put in the Action classes or validator framework can be used.
4. Expression Language
strut 1.x– Jstl(Java Standard Tag Library) is used for expression language.
struts 2.x– Also uses OGNL (Object Graphic Notation Language) as expression language and it is stronger then JSTL. But struts 2.x can also use JSTL.
5. Configuration File
strut 1.x– The configuration file used is struts-config.xml, it may be “anyname.xml” and is put in side web-inf folder.
struts 2.x-The name of the configuration file is struts.xml and is placed inside web-inf/classes folder. Multiple configuration files can also be used.
6. Action Classes
strut 1.x– Action classes have to extend base abstract class, there by cannot extend any other classes.
struts 2.x– Action classes are more flexible and can be created by implementing Action interface, extending ActionSupport class or by a POJO class just having execute() method.
7. Thread Safety
strut 1.x– Action Classes were singleton and not thread safe. Only one instance of a class is used to handle all requests to an Action.
struts 2.x– Action objects are instantiated for every request, so there are no thread-safety issues.
8. Type Conversion
strut 1.x– Properties in ActionForm are generally Strings. Commons-Beanutils is used i struts 1 for type conversion.
struts 2.x– OGNL is used for type conversion. Struts 2 includes converters for common object types and primitive data types.
9. Servlet Dependency
strut 1.x– Action classes execute method has parameters of type HttpServletRequest and HttpServletResponse. So struts 1.x actions has a dependency on servlet api.
struts 2.x– Action class in struts 2 don’t have servlet dependency, because its execute() method doesn’t accept any parameters. But if required Struts 2 Actions can still access the request and response.
10. View
strut 1.x– Generally JSP pages are used for views.
struts 2.x– There is support for multiple view technologies like velocity, Freemarker, jasper reports, jsp etc.
nita says
Nice explanation!!!