Wednesday, 24 August 2011

Diff between struts1 and struts2


Those who don't have knowledge on Struts leave this topic as of now.But those who are all get confused with struts1 and struts2,i hope this definitely will helpful .And there are lot of difference between struts1 and struts2 and each has its own advantages and each developing simultaneously.And don't assume if you know struts2, struts1 is simple and vice versa.

Few diff between struts1 and struts2 are listed below.

Feature
Struts1
Struts2
Action
Action class extends abstract class
(Action Form and Action class are different)
Action class implements Action interface        (Same class can be used  for both Action Form and Action class)
Threading Model
Strtus1 Actions are singleton. So single object is created for all requests for that action. So care to be taken to make the Action resources thread safe and  synchronization
A separate object is created for each request. So no need to worry about the synchronization problem
Servlet Dependency
In Struts1, Actions are dependent on the servlet API because request and response object are passed to the execute method
Request and response object are not explicitly passed to the action execute method. But if want they can use request and response object
Expression Language
Struts 1 integrates with JSTL EL.So struts1 can use EL
Struts2 uses most powerful expression language called OGNL (object Graph Notation Language)
Type Conversion
All the form properties (All the properties in the Action form) are in the form of Strings
OGNL can be used for type conversion
Validation
In Struts1, Validation is done by using validate() method in action form or by using validation.xml and struts_validation.xml.Here chaining of validation on sub objects is not allowed.
Here validation can be done using validate() method or by using XWork validation framework.Using XWork validation chaining of validation is allowed on the sub objects
Control of Action execution
Each module in struts1 has separate request processor(life cycle).So all the actions in that module must share the common lifecycle
In struts2, different life cycles are created for each action using interceptor stacks.

Thanks

No comments:

Post a Comment