Struts (also known as Apache Struts or Struts 1) is a cross-platform open source framework written in Java, which is intended for developing Java EE web applications. It was one of the initial Java EE web application frameworks. But few years later, Struts2 (or Struts version 2) arrived, and it was a completely different and highly improved web application framework. It had addressed few issues that were perceived as deficiencies in the initial version. Now, Struts2 is being used very heavily for developing Java EE applications in the world.
What is Struts?
Struts (Struts 1) framework was one of the initial web application frameworks for developing Java EE web applications. Struts framework encourages the usage of MVC (Model-View-Controller) architecture. It is an extension of Java Servlet API. Craig McClanahan is the original creator of Struts. Initially it was known as Jakaratha Struts and was maintained under Jakarta Project of Apache Software Foundation. It is released under Apache License 2.0. Struts framework is called a request-based framework, and it is made up of three main components: a request handler, a response handler and a tag library. Standard URI (Uniform Resource Identifier) is mapped to a request handler. Response handler is responsible for transferring control. To create interactive applications with forms, the features offered by the tag library can be utilized. Struts support REST applications and various technologies like SOAP, AJAX, etc.
What is Struts2?
Struts framework was perceived to contain certain limitations (mainly the lack of separation between the presentation layer, request handling layer and the model) by the Java EE developers at that time, and consequently few years later Struts2 arrived. Actually, Struts2 was completely different from Struts. In fact, they did not even share the same code base because Struts2 was simply the result of renaming the WebWork 2.2 framework (i.e. WebWork and Struts communities who worked separately for some time ultimately joined hands to come up with Struts2). Its current stable release is version 2.2.3, which was released in May, 2011.
What is the difference between Struts and Struts2?
One of the many problems of Struts framework was the need for programming to abstract classes instead of interfaces. This was solved by Struts2 framework. For example, Struts framework required Action classes to be extended from the abstract base classes, but Struts2 Actions can implement an Action interface. Due to the differences in the threading model between the two versions thread-safety issues that came up in Struts framework regarding Action objects does not occur in Struts2 framework. The reason is Struts2 Action objects are instantiated for each request, while an Action in Struts framework has only one instance to handle all requests for that Action. Unlike the Actions in Struts framework, Struts2 Actions are not dependent on the Servlet API.
Testability of Struts2 framework is comparatively higher than Struts framework. You can test Struts2 Actions simply following the three steps: instantiation, setting properties and invocation of methods. Harvesting input is easier in Struts2 framework as Action properties are used as input properties, without having to keep a second input object. Apart from the support for JSTL integration (which is present in Struts), Struts2 framework can use more powerful and expressive OGNL (Object Graph Notation Language). For type conversion, Strut and Strut2 use Commons-Beanutils and OGNL, respectively. Because of these improvements, Struts2 framework is considered a highly mature framework and it is very popular among Java EE programmers. On the other hand, Struts framework is now considered obsolete.