Difference between struts1.x and struts2.x

Source: Internet
Author: User
Tags garbage collection

http://www.geekinterview.com/question_details/64360

eature Struts 1 Struts 2 Action ClassesStruts1 extends the abstract base class by its action class. The problem with STRUTS1 are that it uses the abstract classes rather than. While in the Struts 2 an action class implements a action interface along with the other interfaces the use optional and custom servi Ces. Struts 2 provides a base Actionsupport class that implements commonly used interfaces. Although an Action interface is notNecessary any POJO object along with a execute signature can be used as a Struts 2 Action object.Threading ModelStruts 1 Actions are singletons therefore they must is thread-safe because only one instance of a class handles the RE Quests for that Action. The singleton strategy restricts to Struts 1 Actions and requires extra care to make the action resources thread safe or s Ynchronized while developing an application. Struts 2 doesn ' t have thread-safety issues as Action objects are for each request. A servlet container generates many Throw-away objects per request and one more object does not impose a performance penalt Y or impact garbage collection.Servlet DependencyThe Actions are dependent on the servlet API because HttpServletRequest and HttpServletResponse are passed to the Execute Metho D When a Action is invoked therefore Struts1. Container does not treat the Struts 2 Actions as a couple. The Servlet contexts are typically represented as simple Maps that allow the Actions to is tested in isolation. Struts 2 Actions can still access the original request and response if required. While other architectural elements directly reduce or eliminate the need to access the httpservetrequest or httpservletres Ponse.testabilitySTRUTS1 application has a major problem while testing the application because the "Execute method" exposes the Servlet API. Struts TestCase provides a set of mock object for Struts 1. To test the Struts 2 Actions instantiate the Action set the properties and invoking methods. Dependency injection also makes testing easier.Harvesting InputStruts 1 recieves an input by creating a Actionform object. Like the action classes all Actionforms class must extend a actionform base class. The other JavaBeans classes cannot is used as actionforms while developers create redundant classes to receive the input. Dynabeans is the best alternative to create the conventional actionform classes. Struts 2 requires Action properties as input properties that eliminates the need of a second input object. These Input properties May is rich object types since they may have their own properties. Developer can access the Action properties from the Web page using the Taglibs. Struts 2 also supports the Actionform pattern POJO form objects and POJO Actions as.Expression LanguageStruts1 integrates with JSTL so it uses the JSTL EL. The EL has basic object graph traversal but relatively weak collection and indexed property support. Struts 2 can use JSTL but the framework also supports a more powerful and flexible expression language called "Object Grap H notation Language "(OGNL).Binding values into viewsStruts 1 binds objects into the page context by using the standard JSP mechanism. Struts 2 uses a valuestack technology to make the values accessible to the TAGLIBS without coupling the view to the object To which it is rendering. The Valuestack strategy enables us to reuse views across a range of types have same property name but different Types.Type ConversionStruts 1 Actionform properties are almost in the form of Strings. Commons-beanutils are used by used by Struts 1 for type conversion. Converters are per-class which are not configurable/per instance. Struts 2 uses OGNL for type conversion and converters to convert Basic and common object types and primitives as.ValidationStruts 1 uses manual validation that are done via a validate method on the Actionform or by using a extension to the Commo NS Validator. Classes can have different validation contexts for the same class while chaining to validations on sub-objects is not allo Wed. Struts 2 allows manual validation the Validate method and the Xwork framework. The Xwork Validation Framework allows chaining of validations into sub-properties using the validations for the PR Operties class type and the validation context.Control Action Execution Each module in Struts 1 has a separate Request processors (lifecycles) while the "all" Actions in the module must share the Same lifecycle. In the Struts 2 different lifecycles are created on a per Action basis via interceptor Stacks. Custom stacks are created and used with different Actions as

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.