What are the differences between struts 1 and struts 2 from developer's perspective. 2 differences I can point out are:
1) For checking on ever page whether user has logged in or not Struts 1 uses Login Filters whereas in Struts 2 we would do this using Interceptors.
2) Data from form does not need to have properties in form bean.Instead it should have properties in Action class
3) Developer does not need to care about synchronizatin in struts 1 whereas in struts 2 one needs tp care about synchronization.
What else does developer doing transition from struts 1 to struts 2 need to keep in mind.
In struts 1: execute method was compulsory.For each small operation a separate Action class should be created with its execute method. Suppose it is UserRegistration.Then for addUser,deleteUser,modifyUser,listUserdifferent classes should be created.
In Struts 2: Since execute method is not compulsory. A single action class will have methods for addUser,deleteUser,modifyUser ,listUser.So in case of struts 2 for UserRegistration there can be just 1 action class and all methods inside this. In such a case when all functionality will be inside methods addUser,deleteUser,modifyUser ,listUser which would be returning success failure etc then what would the execute method be doing?Or should it be omited in such a case.
Monica. Shiralkar wrote:
Developer does not need to care about synchronizatin in struts 1 whereas in struts 2 one needs to care about synchronization.
I couldn't understand this can someone clarify me , this point seems to be vaguely written.
I'm not sure what Monica means about synchronization. If she means the thread model, one must understand how Struts works in order to keep users from interfering with each others requests. In Struts 1, there is only one instance of an Action created, so one must be careful to either create resources in the execute method or use the synchronize keyword to limit access. If one uses instance-level resources, it is very easy to create race conditions.
In Struts 2, an instance of the action is created with each request, so one is not so concerned as much with thread safety (though one can certainly create problems, particularly with static resources).
Joined: Jul 07, 2012
Thanks. And yes I meant the above with synchronization.