Major differences between Struts 1 and Struts framework in Java
Explain the difference between Struts 1 and Struts 2 is one of the common Struts interview questions with respect to Java JEE interviews. Be prepared to face this question if you have mentioned Struts in your resume and Struts 1.x was a famous MVC framework for Java web application in the previous ten years but when Spring MVC arrived, Struts lost its importance.
1. Front Controller :
In Struts 1x Action Servlet one of the key structures are front controller especially for every request, there is a new bean instance formed for making hold parameter that is within reach for the Action class. In Struts 2.X FilterDispatcher takes the form of front controller. A new instance received from a request of action class is developed and param interceptor loads all the parameter with the request to the field of action instance.
2. Action Classes:
A major difference between Struts 1.x and Struts 2 framework is that Struts1's Action classes are pushed for an abstract class extension that makes it nonextendable. There is more flexibility in Struts 2 action classes and make them by Action interface implementation, with an ActionSupport extension class or just by having executed () method.
3. Thread Safety :
Difference between Struts 1 and Struts 2 is another significant part which is very much overlooked by Java developers. There is no thread safety and Singleton in Struts 1 Action classes and the developer' side required to show some extra care for neglecting the side effects due to multithreading. Struts 2 action classes when requested gets instantiated and there is no multithreading and sharing over here, therefore, they are safe in a thread.
4. Servlet API coupling :
The basic level difference with respect to framework between Struts 1 and Struts 2 is that there is a tight coupling in Struts 1 API and Request and Response objects are shifted to action classes execute () method. Struts 2 API, on the contrary, is coupled loosely with Servlet API and there is no manual intervention in mapping the form bean data to action class Java bean properties that are used mostly.
5. Testing :
When code quality and productivity is a concern the major difference over here is testing. Struts 1 action classes would be tough to test due to Servlet API coupling, but Struts 2 Action classes are like normal Java classes and it can be tested instantly and setting their properties.