Narayana Tutorial

Online Java Tutorial Blog

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

  • MVC is popular as it isolates the application logic from the user interface layer.
  • Supports separation of concerns.
  • Each layer is an isolated it means that one layer changes will not impact other layer i.e changes will be independent.
  • We can change / modify presentation / user interface (UI) easily without affecting business logic and vice versa.
  • Better and easier code maintaining.
  • Code reuse
  • Less coupling between the layers
  • By separating concerns into 3 distinct pieces, you also facilitate true unit testing. Your Presentation layer can be tested free of the Model or Controller, and vice-a-versa.

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

 

Narayanaswamy

Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development.

I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

Leave a Reply

Narayana Tutorial © 2018 Frontier Theme
Show Button
Hide Button