I would like to know the difference between Struts 1.x and Struts 2.x
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.
It's a totally different web framework... Struts2 is basically the old Webwork.
Some differences:
- Struts2 works with POJOs, no more ActionForms. All attributes from the requests are populated in "standard" Java classes.
- Struts2 actions are not coupled with the Servlet API, they do not receive HttpServletRequest and HttpServletResponse as parameters. Also, they are stateful, (Struts 1 actions were stateless).
- Struts2 have a lot of enhancements like the Interceptor API, plus lots of integrations.
- Configuration is totally different.
I recommend you to "retire" Struts1 in favor of modern web frameworks.
© 2022 - 2024 — McMap. All rights reserved.