Mr. Journo
Home Education Best Ways of Learning Strut Frameworks in Java
Education

Best Ways of Learning Strut Frameworks in Java

by Digital raghul - 21 Jul 2022, Thursday 235 Views Like (0)
Best Ways of Learning Strut Frameworks in Java

What is the struts Framework in Java?

A beautiful, extendable, open-source framework for creating Java web applications is called Struts. It is used to create web applications with the Model-View-Controller (MVC) architecture.


Webwork 2 was the previous name for Struts 2. Later, the two frameworks—webwork and struts—were integrated to create a new version of struts, known as struts 2.

Webwork + Struts 1 = Struts 2.

Features of Struts 2.

1. POJO form :

     Action forms are not required in Struts 2. The form input can be received by any POJO class.

2. POJO Activities:

      In Struts 2, an Action class is not required. An Action class can be created from any POJO class.

3. Enhanced Support for Tags:

        Struts 2 offers a number of different tags to make the development process easier.

4. Support for Templates:

     The template capability for creating common look views is provided by Struts 2.

5. Support for Simple Integration:

     Applications built using Struts 2 can simply be integrated with frameworks like spring, hibernate, etc.

6. AJAX assistance:

     Ajax functionality is offered by Struts 2 through ajax tags.

7. Support for Enhanced Results:

     Jasper Reports, JFreeChart, and other tools can be used to produce more unique results.


Sturct2 Pros:

1. Action classes in Struts 1 must extend an abstract base class.

2. Because Struts 1 Action is a singleton, it is thread-safe.

3. Because the HTTP Servlet Request and HTTP Servlet Response must be given in the execute function, Struts 1 Action depends on the servlet API.

4. To receive form input, Struts 1 uses the Action Form's object.

5. The JSTL expression language is used by Struts 1.

6. Struts 1 binds objects into the page context using the common JSP technique.

7. Type conversion is less flexible with Struts 1.

8. The Action Form is manually validated using the validate function by Struts 1.

Struct2 Cons:

1. Action classes in Struts 2 are not required to extend any abstract classes. They might use the Action interface.

2. Actions in Struts 2 are not thread-safe.

3. The servlet API is not required for Struts 2 Actions.

4. Action Form is not required with Struts 2.

5. "Object Graph Notation Language" (OGNL) expression language is used by Struts 6. Value Stack technology is used by Struts 2 to link values to views.

7. A more flexible sort of conversion is offered by Struts 2.

8. By utilizing the validate function, Struts 2 supports manual validation. The XWork Validation framework is also included..

Basic MVC Architecture in Struts2:

The software design pattern is known as Model View Controller, or MVC as it is more often known as used for creating online applications. The following three components make up a 

Model View Controller pattern:

1. Model — The data are maintained at the lowest level of the pattern.

2. View — This is in charge of showing the user all or a portion of the data.

3. Controller – The computer program that manages how the Model and View interact.



The model: 

      The model is in charge of looking after the application's data. It responds to the view's request as well as the controller's requests for it to update itself.

The View: 

     This term refers to the format in which data is shown after being selected for presentation by a controller. Like JSP, ASP, and PHP, they are script-based templating systems that are very simple to connect with AJAX technology.

The Controller: 

     The Controller is in charge of interacting with the data model objects and responding to user input. The input is received by the controller, which then verifies it before carrying out the business activity that changes the state of the data model.


Sturt2 Architecture:

 Struts2 is a pull-MVC (or MVC2) framework at the most basic level. The five main central elements make up Struts2's implementation of the Model-View-Controller pattern:


1. Behavior

2. interception 

3. Value Stack/OGNL 

4. Results / Types of results

5. Examine technology

Although there is some overlap, Struts 2 differs slightly from a standard MVC framework in that the action assumes the role of the model rather than the controller.

The Model, View, and Controller components of the Struts2 high-level architecture are shown in the following diagram. This model is built with actions, the controller uses a Struts2 dispatch servlet filter together with interceptors, and the view combines result kinds and results. The value stack and OGNL offer a connecting, enabling, and common thread.

Sturt2 Interceptors

Conceptually, interceptors are equivalent to servlet filters or the JDK's Proxy class. Crosscutting functionality can be implemented separately from the action and the framework thanks to interceptors. The following can be accomplished via interceptors:

1. Prior to calling the action, preprocessing logic is provided.

2. provide logic for postprocessing after the action is called.

3. catching exceptions to allow for alternative processing.

Frequently used strut default interceptors 2.

1. Alias: It enables the use of several alias names for the same parameters across requests.

2. Checkbox: It is used to manage checkboxes by adding a false value for ticked but unchecked checkboxes.

3. Conversion error: This is employed to include conversion errors in the action's field errors.

4. Execute and wait: This technique is used to direct users to a waiting page while activity is being carried out.

5. i18n: It keeps track of the session's active locale. It offers tools for localization and internationalization.

6. debugging: It offers the developer debugging support.

7. Exception: It offers the ability to automatically handle exceptions by mapping an exception from an operation to the outcome.

8. file uploading capability: This feature allows for file uploading.

9. Logger: The logger outputs the name of the executed action.

10. Validation: It offers assistance with validation.

Result Types:

In the Struts2 MVC framework, the tag serves as a view. The business logic must be carried out by the activity. The view is displayed using the tag when the business logic has been carried out.

The findings frequently have some navigational guidelines attached. For instance, there are three possible results if the action method is to authenticate a user.

1. Authenticated Easily

2. Failed Login - Wrong Username or Password

3. Locked Account

 However, JSP is not a requirement for using Struts2 as the view technology. The MVC paradigm's primary goal is to keep the layers distinct and highly flexible. For a Web2.0 client, for instance, you could want to provide XML or JSON as the output. In this situation, you may accomplish this by creating a new result type for XML or JSON.

The default result type dispatcher, which is used to send results to JSP pages, is one of the predefined result types that Struts include. The common options for using various markup languages with Struts for the view technology to deliver the results include Velocity, Free Maker, XSLT, and Tiles.


Annotations

As previously noted, Struts offers two types of configuration. The struts.xml file is traditionally used for all setups. In the tutorial so far, we have seen a tonne of examples of that. The Java 5 Annotations feature is the alternate method of customizing Struts. We may achieve Zero Configuration by using the struts annotations.

Make sure the following jar files are present in your Web Content/WEB-INF/lib folder before you begin utilizing annotations in your project:

1.struts2-convention-plugin-x.y.z.jar

2. Asm-x.y.jar

3. antlr-x.y.z.jar

4. the file upload-x.y.z.jar

5. Commons-io-x.y.z.jar

6. commons-lang-x.y.jar

7. commons-logging-x.y.z.jar

8. Commons-logging-API-x.y.jar 

9. freemarker-x.y.z

10. The javassist-.xy.z.GA 

11. Ognl-x.y.z.jar 

12. Struts2-core-X.Y.Z.jar 

13. The file xwork-core.x.y.z.jar