Open In App

Struts 2 Features

Last Updated : 26 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Struts is a popular open-source framework of Java for developing large scale web-applications. It provides a framework for implementing MVC-architectured applications promoting the separation of concerns between business and presentation logic. Struts is an essential framework for building J2EE (Enterprise Edition) based web apps.

Struts 2 comes with a complete cycle development framework, from design to deployment and maintenance of the application, Struts 2 has full support for everything. It was originally known as “web work 2”.

In this article, we’ll look at the features of Struts 2.

Struts-2-Features

Features of Struts 2

There are certain Features of Struts 2 mentioned below:

1. MVC Architecture Support

Struts 2 is built on developing applications based on the MVC architecture, providing a separation of concerns between the business logic and presentation logic. Business logic is contained inside the component called – ‘Controller‘ or the ‘Action Servlet‘, and the Presentation logic can be defined flexibly inside any view-related file such as HTML or JSP.

2. Action Support

Actions are special Java classes just like REST APIs, that provide the business logic to handle all the incoming requests and generate appropriate responses. These actions are called when a specific URL is hit. In struts 2, the Action class is the POJO (Plain-old-Java-Object) and you do not have to mandatorily implement an action interface.

3. Tag Support

Struts 2 has custom tag support that simplifies the process of writing dynamic web pages in less code. These tags also help in integrating the business logic alongside the presentation layer. Ex: Form tags, UI Tags, Data Tags, Control Tags, Template tags, etc.

4. Ajax Support

Struts 2 comes occupied with AJAX (Asynchronous JavaScript & XML) support, which is more efficient for developing dynamic and interactive applications without writing extensive JavaScript code. It is facilitated by a powerful library – Dojo Toolkit for a rich and responsive user interface. Some of the most common tags: are <sx: autocomplete>, <sx: div>, etc.

5. Simplified Configuration

Struts 2 provides a deployment descriptor file for simplifying initial configuration and reducing boilerplate code. It initializes the resources in XML format, which is done by scanning Java packages. On the other hand, you can also take control of the configuration file by providing an external application-config file. This simplified procedure for configuration allows the developer to focus on the business logic rather than configuring everything in detail.

6. Integration

It has a well-defined control on integrating with other Java frameworks such as Spring, Hibernate, JPA, etc. This enables the developers to leverage the strength of other robust frameworks.

7. Interceptors

Interceptors are additional (and optional) components that can be added to the application to intercept requests & responses for pre-post processing purposes. Intercepting is done mainly for logging, authentication & authorization, monitoring, debugging, and troubleshooting related work.

8. Result Types

Result types represent the responses. Responses can be generated in different formats like XML, JSON, and HTML. This allows the developer to use the appropriate technology and implement the view in any language.

FAQs on Struts 2 features

1. What is the difference between Struts 1 and Struts 2 features?

The major differences between supports two are as follows :

  1. POJO is available in Struts2 but not in Struts 1
  2. Struts 2 classes directly map to a POJO, thereby offering more flexibility unlike Struts 1 in which the classes are mapped with a JSP
  3. In Struts 1, for the presentation layer, only JSPs can be used but Struts 2 offers us more technologies such as velocity, freemaker, Jasper reports, etc.

2. How does Struts 2 supports AJAX?

Struts 2 provides supports for AJAX using a JavaScript library – Dojo Toolkit. It has various tags for developing an application in less code.

3. How does Struts 2 handle form submission and data binding?

Struts 2 handles this by automatically mapping the parameters with the action properties. The framework utilise the Object Graph Notation Language (OGNL) when the form is submitted by the user.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads