Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Model 1 Architecture
2.1.
Advantages of Model 1 Architecture
2.2.
Disadvantages of Model 1 Architecture
3.
Model 2 Architecture
3.1.
Advantages of Model 2 Architecture
3.2.
Disadvantages of Model 2 Architecture
3.3.
Solution of Model 2 Architecture
4.
Frequently Asked Questions
4.1.
What is Struts?
4.2.
What is Web Framework?
4.3.
What are scriplets?
4.4.
What is API?
4.5.
What is MVC?
5.
Conclusion
Last Updated: Mar 27, 2024

Model 1 and Model 2 Architecture

Author Sanchit Kumar
0 upvote

Introduction

There are many Java frameworks to create web applications one such framework is Struts. Before creating web applications, we should be familiar with design models or design patterns. There are two approaches for building web applications, Model 1 Architecture and Model 2 (MVC) Architecture. So, let us learn about these two approaches one by one.

Struts coding ninjas

Model 1 Architecture

Model 1 Architecture is one of the two approaches for building web applications.

Early web application design considered the JSP page as the centrepiece of the entire application. The JSP page, also known as Model 1 architecture, is in charge of extracting HTTP request parameters, calling the business logic, and managing the HTTP session, in addition to containing the display elements to output HTML. 

Model 1 architecture

Although Model 1 Architecture is best suited for simple applications, it usually leads to a considerable amount of scriptlets, especially if there is a substantial amount of request processing to be performed.


Model 1 Architecture Illustration - 

illustration of model 1 architecture
  1. The browser sends an HTTP request to JSP
  2. JSP communicates with JavaBeans and calls the business logic
  3. JavaBeans connects to the database and gets/saves data
  4. The response generated by the JSP is sent to the browser

Advantages of Model 1 Architecture

  • Quick and easy to develop simple web applications.
  • Provides better separation of concern - presentation and business logic can be easily separated.

Disadvantages of Model 1 Architecture

  • Navigation control is decentralised - Since the logic to decide the next page is contained on every page, that means if the name of a JSP page is changed that is referred to by other pages, we need to update it in all the pages that lead to the maintenance issue.
  • Time-consuming - We need to invest extra time to develop custom tags in JSP in order to avoid using the scriptlet tag.
  • Hard to extend - It is suitable for simple applications but not for large ones.

Model 2 Architecture

Model 2 architecture

Model 2 (MVC) Architecture is based on the MVC (Model View Controller) design pattern. It consists of three modules Model, View and Controller.

  • Model - The model represents the application's state (data) and business logic.
  • View - The view module is responsible for displaying data, i.e. it represents the presentation.
  • Controller - The controller module serves as an interface between Model and View. It intercepts all the requests, i.e., receives input and instructs Model/View to change accordingly.


Model 2 Architecture Illustration - 

Model 2 Architecture

Advantages of Model 2 Architecture

  • Navigation control is centralised - The logic to choose the next page is now only included in the controller.
  • Collaboration amongst multiple developers is easier.
  • Easy to maintain, extend and test.
  • Debugging is easier as multiple levels are written properly in the application.

Disadvantages of Model 2 Architecture

  • It is challenging to comprehend the MVC design.
  • We must write the controller code from scratch. If we modify the controller code, recompiling the class and redeploying the application are required.

Solution of Model 2 Architecture

Configurable MVC Components

Declarative approaches are used to define view components, request mapping etc. It resolves the issue of Model 2 architecture. The configurable MVC support is provided by the Struts framework. In struts 2, we define all the action classes and view components in a dedicated XML file (struts.xml).

Also see, Clean Architecture

Frequently Asked Questions

What is Struts?

Struts is a free, open-source framework for web applications written in Java. Apache Software Foundation maintains this framework.

What is Web Framework?

It is a software framework, also known as a web application framework (WAF), which helps in the creation of web applications, including web APIs, web services and web resources.

What are scriplets?

Scriplets are Java code embedded within HTML code in the JSP page.

What is API?

API (Application Programming Interface) is a means of communication between two or more computer programs. It is a kind of software interface that provides a service to other software programs.

What is MVC?

It stands for Model, View, and Controller and is known as the software design pattern for creating web applications.

Conclusion

In this article, we discussed Model 1 Architecture and Model 2 Architecture. We learnt about two approaches for building web applications, Model 1 Architecture and Model 2 Architecture, that would be helpful to know before we create web applications using the Struts Java web framework.

To learn about various Java frameworks, click here. See the official website for documentation and other information about Struts.

Nevertheless, you may consider our paid courses to give your career an edge over others.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Coding Ninjas
Live masterclass