Apache Struts 2 is an elegant, extensible framework for creating enterprise-ready Java web applications. The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time.
Apache Struts2 was originally known as WebWork 2. After working independently for several years, the WebWork and Struts communities joined forces to create Struts2. This new version of Struts is simpler to use and closer to how Struts was always meant to be.
Struts 2 is a pull-MVC framework. i.e. the data that is to be displayed to user has to be pulled from the Action.
Struts2 supports annotation based configurations which are easy to create and more intuitive. Action class in Struts 2 act as the model in the web application. Unlike Struts, Struts 2 Action class are plain POJO objects thus simplifying the testing of the code. Struts2 also comes with power APIs to configure Interceptors that reduce greatly the coupling in application. The view part of Struts 2 is highly configurable and it supports different result-types such as Velocity, FreeMarker, JSP, etc.
MVC : Model View Control, am giving real time definitions, i don’t want to confuse you by saying lines of definitions
Model: Will concentrates on business logic of an application, am going to take bean as model.
View: will take cares the presentation, i mean visible part, we are going to use jsp as view for these struts 2 applications. The view part provides interface with the outside world to our application. A single model can have multiple view for different purposes. The view object defines the way how the data is to be presented. View object is responsible for maintaining the consistency in data presentation whenever the model changes.
Controller: is a component, which contains all primary logic’s required, like sessions and security and also it contains the entire flow of applications, we are going to use servlet as controller for these struts 2 applications. The controller controls the user interaction between the view and model. The controller does not includes any business logic. It also strictly deals with exposing of methods included in the model to the user through the view. The controller controls the updation of a particular parameter in the view which is then displayed by a view. Based on the outcome of the interaction with the user and model, the controller determines the appropriate view.
To building our own MVC Framework, there is a client call the handler to handle parameters. Handler is like a controller it is routed by the route configuration file, this file has all the configuration for routing the specific controller and services. And another level is the Model classes, these are the business classes , in these define all the business logic these logic apply to the request parameters and passes to view module, view module has different tag libraries, please see in the below pics.
All requests passes through interceptors and struts 2 configuration is take care about all request and interact to specific action class and action class return the result to view jsp file.
Here is the Request Lifecycle in Struts 2 applications:
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…