Best Struts2 Training In Chennai Adyar With Placement

Introduction To Struts Framework

Let us see the quick and brief introduction to struts 2 framework, struts is an open source framework given by Apache software foundation under one of its projects called Jakarta. Struts is the frame work, used to develop web applications for java with mvc2architecture.

Actually struts 1 was introduced in 2004 and this framework is failed to satisfy the needs of customers in today’s worlds, finally Apache joined with OpenSymphony and created struts2.x.

struts 2 = webwork2 + struts 1

webwork2 is the framework from OpenSymphony, java based mvc2.

You know what, struts 2 is not an extension of struts 1, its the combination of struts 1 and webwork2 some features taken from struts1 and some from webwork2 and finally released this struts2 frame work.

Types of frame works

Frameworks are divided into 2 types,

  • Invasive
  • Non-Invasive

Invasive means, it will force the programmers to create their classes by extending or implementing from per-defined classes or interfaces provided by that frame work. Non-Invasive means it wont forces the programmer to extend or implement its own classes or interfaces.

Struts is the type of Invasive frame work.

Why struts so popular

  • Struts supports extensive validations where other frame works doesn’t
  • Having inbuilt support for I18N
  • Struts 2 actions classes are spring friendly so we can easily integrate
  • In build AJAX themes to make the applications more dynamic
  • Finally good frame work for front end based applications, i will explain this point later hah

Struts 2 based on MVC 2 architecture

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

Controller: is a component, which contains all primary logic’s required, like sessions andsecurity and also it contains the entire flow of applications, we are going to use servlet as controller for these struts 2 applications.

Hope you are clear, don’t think much see the next tutorial am promising you that i will make you to understand this struts2 better than what you are expecting

Struts 2 Architecture and Flow

The architecture and flow of struts 2 application, is combined with many components such as Controller, ActionProxy, ActionMapper, Configuration Manager, ActionInvocation, Inerceptor, Action, Result etc.

Here, we are going to understand the struts flow by 2 ways:

  1. struts 2 basic flow
  2. struts 2 standard architecture and flow provided by apache struts

Struts 2 Architecture

From a high level, Struts2 is a pull-MVC (or MVC2) framework. The Model-View-Controller pattern in Struts2 Training is realized with following five core components:

  • Actions
  • Interceptors
  • Value Stack / OGNL
  • Results / Result types
  • View technologies

Struts 2 is slightly different from a traditional MVC framework in that the action takes the role of the model rather than the controller, although there is some overlap.

The above diagram depicts the Model, View and Controller to the Struts2 high level architecture. The controller is implemented with a Struts2 dispatch servlet filter as well as interceptors, the model is implemented with actions, and the view as a combination of result types and results. The value stack and OGNL provide common thread, linking and enabling integration between the other components.

Apart from the above components, there will be a lot of information that relates to configuration. Configuration for the web application, as well as configuration for actions, interceptors, results, etc.

This is the architectural overview of the Struts 2 MVC pattern. We will go through each component in more detail in the subsequent chapters.

Request life cycle

Based on the above digram, one can explain the user’s request life cycle in Struts 2 as follows:

  • User sends a request to the server for requesting for some resource (i.e pages).
  • The FilterDispatcher looks at the request and then determines the appropriate Action.
  • Configured interceptors functionalities applies such as validation, file upload etc.
  • Selected action is executed to perform the requested operation.
  • Again, configured interceptors are applied to do any post-processing if required.
  • Finally the result is prepared by the view and returns the result to the user.

Struts 2 basic flow

Let’s try to understand the basic flow of struts 2 application by this simple figure:

  1. User sends a request for the action
  2. Controller invokes the ActionInvocation
  3. ActionInvocation invokes each interceptors and action
  4. A result is generated
  5. The result is sent back to the ActionInvocation
  6. A HttpServletResponse is generated
  7. Response is sent to the user