Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between Struts 1.x and Struts 2.x

I would like to know the difference between Struts 1.x and Struts 2.x

like image 543
Ashvin Ranpariya Avatar asked Apr 27 '09 12:04

Ashvin Ranpariya


People also ask

What is the difference between Struts 1 and Struts2?

Struts 1 supports separate Request Processors (lifecycles) for each module, but all the Actions in the module must share the same lifecycle. Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks. Custom stacks can be created and used with different Actions, as needed.

How do I migrate from Struts 1 to Struts 2?

The easiest approach to migration is to add the Struts 2 JAR file (available from the Apache Project; see Resources) to the application and migrate code on one page at a time. Many changes are just a matter of removing Struts 1 classes and tags that are not needed and including what is required for Struts 2.

What is the difference between servlet and struts?

A Servlet is a technology and Struts is a framework which relies on or makes use of Servlets.


1 Answers

The major difference is that in Struts1.x the request directly goes to the servlet, whereas in Struts2.x the request and response traval though the stack of interceptor or filter. The regular logic can be placed in Filter classes and developer can concentrate on the Business Logic. Besides this there is also differences in directory structure.

It is better to know the differences between Struts1.x and Struts2.x topic wise. Here's a cite of http://www.geekinterview.com/question_details/64360:


1. Action Classes

In Struts 1.x the action classes should extend Action (or DispatchAction) class and the execute method have number of parameter and a ActionForward return type , but In struts 2.x the action class can also be simple pojo having execute method returning only a string without any input parameter.


2. Servlet Dependancy

Container does not treat Struts2.x, unlike that of Struts1.x, Actions as a request / response couple and struts2.x action can still access the original request and response.


3. Getting Input

  • In Struts1.x form beans are used to define properties, getters & setters, in struts2.x getters/setters are defined in action classes itself.
  • Struts1.x form beans class must extend ActionForm or ValidatorForm, but Struts2.x beans can also be POJO.

4. Testability

  • In Struts1.x execute() method exposes the servlet API for testing.
  • Struts2.x Dependancy Injection be used to simplify the testing process.

5. Expression Languages

  • Struts1.x JSTL as its expression language, where as Struts2.x uses OGNL(Object Graphic Notation Language) as its expression language which is very strong than JSTL.
  • Struts2.x can also use JSTL.

6. Type Conversion

  • In Struts1.x properties are almost in String form, Convertors are per class which are not configurable.
  • Struts 2.x uses OGNL for type conversion

7. Validation

Server side validation are made in action classes in Struts2.x, a much simpler way.

like image 140
Jitendra Avatar answered Oct 11 '22 01:10

Jitendra