Struts 2 Tutorial

Struts is mainly used to create java-based applications. It is the complete framework used in activities ranging from development to deployment and maintenance. Struts is the MVC (Model View Controller) based framework. It is used for separating UI from the main application. It makes the application easy to understand. Model does the function of handling the data of the application. The model gives response for request from view and also respond to controller instruction. The view uses scripting technologies like JSP, ASP, PHP. The controller gives a response to input from the user. It performs business operations. Struts framework was originally developed by Craig McClanahan and later it was given to Apache foundation. Struts support validation, integration, POJO-based actions, and AJAX. It is used with various frameworks such as spring and hibernate. It is the open-source framework used to create flexible web applications. The main objective of the Struts framework is to separate Model, View, and Controller. It separates the user interface from application logic. Thus, it will be easier to deal with Struts.

The 4 main components of any struts project are:

  1. Action: It is used to control the overall coordination between the model, view, and the user. The business logic of an application is included in the Action class.
  2. Interceptors: It is used with Controllers. We can use available interceptors or can create our own interceptors.
  3. View: It is used to interact with the user. Also, it is used to show final results.
  4. Configuration files: Action, View, and controllers are integrated into the configuration file. Different configuration files are struts.xml, struts. properties and web.xml
Introduction to STRUTS

Features of Struts:

  1. Easy Integration: The Struts can be integrated with another framework such as spring, hibernate, Tiles to develop the J2EE applications
  2. Minimal Configurations: Struts don't involve any overhead of the configurations. Most of the settings are done by default and it works with minimum configuration
  3. Integration with View technologies: Different view technologies such as JSP, XSLT, Velocity can be integrated with struts to develop the J2EE applications.
  4. POJO-based forms and actions: In Struts, some actions classes acts as a controller. They are mainly responsible for executing the business logic. The result is then returned with the view which acts as a Model class.
  5. Improved tags and customization: Different tags such as data tag, UI tag, and control tag are used in Struts.
  6. Theme and template support: The three types of templates supported by Struts are xhtml, css_xhtml, and simple. Common look and feel can be implemented using the themes and templates.
  7. AJAX support: AJAX technology is supported by Struts which makes the overall performance faster.
  8. Plugin support: There are various plugins available for struts. The behavior of struts can be enhanced with the use of plugins.
  9. Profiling: For debugging the applications, struts provide an integrated profiling feature. Some debugging tools support integrated debugging.

Advantages of Struts:

  1. Struts Documentation is well maintained and updated and it is very useful for the users who try to develop the Struts framework.
  2. Struts give support of Consistent Approach through MVC based applications
  3. Built-in support for I-18-N is provided by the Struts framework
  4. Struts is an open-source free to use Java framework
  5. Modular development and easier integration with enterprise components is allowed by Struts framework.
  6. Extensible authentication and validation are done
  7. Various Form Field Validation is supported by Struts which are used to check the required values in the form in the required format.
  8. Centralized file-based configuration is supported in Struts framework e.g. Struts values are stored in XML or property files.

Disadvantages of Struts:

  1. Struts applications are hard to benchmark and optimize
  2. Increasing learning curve is the drawback of Struts framework
  3. Struts framework doesn’t support Exception
  4. If we have to use this framework, we must follow all the rules set by this framework
  5. This framework doesn't have a backward flow
  6. Struts framework are less transparent. There are a lot of things happening in the background in struts applications. and not easy to understand
  7. This framework requires more learning. You have to be familiar with JSP, Servlet. Struts 1.3 is not compatible with smaller projects.

Struts 2 Tutorial

Bundled Validators

Control Tags

Data Tags

UI Tags

Interceptors

Misc