Struts2 Tutorial Part 1 – Introduction

Struts2 is a modern framework to develop java based web application. It follows the MVC architecture. If we are aware of jsp/servlet then Struts2 can be easily learned.

Why Struts 2?

We have several methodologies to develop web application. Then why Struts2? Below are the key reasons.

Minimal code

If we setup the Struts 2 environment most of the activities like login verification, authorization flow, pre and post activities will be take care by the framework. We can only concentrate on the real work. (Will learn later in detail)

Compatible with other technologies

Easy to integrate with other technologies like Spring. (Will learn later in detail)

Purely Java based (POJO objects)

Any java object can be a struts2 class. If we aware of java that is enough to use this framework. (Will learn later in detail)

Custom Stuts2 UI tags

– Struts2 provides huge set of custom tags. By using the framework custom tags we can rapidly minimize the code. (Will learn later in detail)

AJAX Support

Stuts2 has inbuilt ajax support. It can be simply used from struts2 custom tag. (Will learn later in detail)

Struts2 also has other benefits.  But in the starting level the above points are enough to understand the usefulness of this framework.

Struts2 against normal jsp/servlet

If you aware of servlet the flow of the application will be controlled by the web.xml file where all the configuration settings will be given. This xml file will be responsible to make sure the user s logged in before accessing particular resource by adding filters.

But Struts2 will provide all these necessary settings by default. The only thing is we have to just write the implementation logic. (When we develop our first Hello World application we will see in detail).

Struts2 Flow

Before understanding the flow we should know the below terms first.

Actions:

Actions are java methods in real, where the real logic will be present.

Interceptors:

Interceptors are the one of the key points in Struts2 framework. In real it is also a java class. The roles of Interceptors are controlling the workflow as well as pre and post processing activities. (Will know details in the Interceptor chapter)

Value Stack:

Where the variable will be stored and retrieved.Struts2-Architecture

Even the above flow looks messy it is simple to understand. Al the requests received will be go to the interceptors we defined before running the actual code. Once the interceptors code executed they will go to the actual code. Finally the control will go to the interceptor in reverse order before sending the response back to the client.

To understand the flow in simple see the image below.
struts-2-request-cycle

With this we will complete the introduction to Struts2. While developing the first Hello World application we will see the flow and other options in detail.

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *