Site icon Narayana Tutorial

What is struts 2 Architecture in java?


Struts 2 Architecture

Struts 2 is an open-source web application framework for developing Java EE web applications and given by  Apache Software Foundation  in 2004 and formerly located under the Apache Jakarta Project and known as Jakarta Struts, it became a top-level Apache project in 2005.

It uses and extends the Java Servlet API to encourage developers to adopt a Model–View–Controller (MVC 2) architecture, combine of both successful WebWork2 and Struts 1.x web frameworks.

Struts 2 = WebWork2 + Struts 1.x

Struts 1.x framework was failed to satisfy the business needs in today’s world so that Struts 2 introduced in 2004.

Actually Struts 2 is not an extension of Struts 1.x, it is the combination of WebWork2 some features and Struts 1.x some features.

Apache Struts 2 was originally known as WebWork2.

Architecture Supports

Struts 1.x, Spring Supports Push MVC and Struts 2.x supports Pull MVC.

Push MVC

In case of Push-MVC the data (Model) is constructed and given to the view layer by the Controllers by putting it in the scoped variables like request or session. Typical example is Spring MVC and Struts1.

Pull MVC

In case of Pull-MVC on the other hand puts the model data typically constructed in Controllers are kept in a common place i.e. in actions, which then gets rendered by view layer.

MVC Description

M(Model)

Business logic of Application i.e stores data that is retrieved according to commands from the controller and displayed in the view.

V(View)

Presentation Layer i.e output presentation to the user based on changes in the model using Jsp, Html, Freemarker, Velocity etc..

C(Controller)

It contains the entire flow of applications i.e will transfer control from the client (browser) to model and vice versa (interactions between the Model and View) and it contains request, response, session and security objects. In struts 2, Servlet is the controller

Advantages of MVC

Prerequisites

A basic understanding of MVC Framework and JSP or Servlet is very helpful.

Software Required

  1. Java Development Kit (JDK) —   Download
  2. IDE (Eclipse or Netbeans) — Eclipse    Netbeans
  3. Apache Tomcat — Download
  4. Struts 2 Related Jars