Struts2 TutorialThe Struts2 is an Open Source web based framework based on Model View Controller (MVC) Design Pattern. The latest stable version of Struts is Struts 2. This project is from Apache and is combination of WebWork 2 and Struts 1. It is highly extensible and flexible framework for web application development.
The key features of Struts 2 are Interceptors, Result Types, easy integration with other framework through plug-in, data validations at client or server side, implementation of Inversion of Control (IoC), Internationalization, and Tiles integration etc. It is a web application framework with tools, and API for creating web application. It implements Front Controller (FC) approach like - Struts 1 and String Web MVC framework.
The Struts 2 action classes are core concepts and represents Model class itself which contains business logic for processing on the data. Action classes act as controller in the MVC (Model View Controller) pattern.
The Inversion of Control (IoC) and Dependency Injection (DI) are programming design pattern, which is used to reduce compiling in computer programs. You do not create object, only describe how to use objects. The container creates the required object whenever is required.
The Struts2 framework provides very important features known Interceptor. It is used to controlling request and response. The Interceptor executed before and after the Action. So It can be used to process some logics on the request before Action and after Action also. It is same as Filter concept of J2EE application. Most of the framework implemented the interceptor functionality.
The Struts2 framework provides powerful tag libraries to create view pages. It can be used to create view pages in very easy.
After executing the Action class, the target view page will be executed based on configuration in struts.xml. The Struts 2 framework provides set of Result types like, chaining, dispatcher, redirect action, velocity and freemarker etc
The exception handling is the common task in any Java based application. The Struts 2 framework provides the simple way to handle any uncaught exceptions generated by a web application and also provides robust exception handling, including the ability to automatically log any uncaught exceptions and redirect the user to a error web page.
Struts 2 framework provides feature to execute method from action class dynamically. Suppose you have five methods (execute, add, delete, update and query) in action class and want to configure in struts.xml file.
The Struts 2 framework provides excellent validation feature. It can be configured vie XML of annotations. You can validate data in action class also through validate () method. The validation concept depends on the validation and workflow interceptor; both are part of the default interceptor stack.
The Struts 2 provides feature t for web application can created for global use. The web content will be changed according to the language selection by the user at run time. To implement the above concept, Struts2 Internationalization and localization is used.
The Apache Tiles is templating framework is used to design several pages in easiest way. It provides features to divide entire page in different sections including title and page can be inserted in the sections at run time. It is used for same look and feel of several pages.
The Hibernate is most popular ORM (Object Relational Mapping) framework in the market. You can integrate it in all Java/J2EE based framework. You can develop with xml configuration or with annotations.
You can inject Session and Transaction in DAO class and it can be configured using annotations, xml and both.
Spring is an Open Source lightweight framework works with all tier software application layers. It provides container to manage bean and uses Dependency Injection (DI).