MVC Architecture Using Servlet And JSP

Web Architecture Models

Different programmers may design an application in different ways. Designing an application depends on how the programmers recognize the problem and approaches for solving that problem. A development model facilitates the design process by separating the code according to the functions performed by different parts of the application.
Two types of development models are used for web applications.

  • Model-1 architecture
  • Model-2 architecture

Model-1 Architecture

Servlet and JSP are the main technologies to develop the web applications. This model uses JSP to design applications which is responsible for all the activities provided by the application. The following figure shows Model-1 architecture.
model - 1 arch

In Model-1 architecture web applications are developed by combining both business and presentation logic. In this model, JSP pages receive requests which are transferred to data sources by JavaBeans. After the requests are serviced, JSP pages send responses back to client.

Advantages

By using this model it’s easy to develop web application.

Disadvantages

  • This architecture is not suitable for large applications.
  • It increases the complexity of the program so it is difficult to debug the program.
  • It needs more time to develop custom tags in JSP.
  • A single change in one page needs changes in other pages. So it is difficult to maintain.

Model-2 (MVC) Architecture

The Model-2 architecture is based on MVC design model i.e. Model, View and Controller.

Following figure shows Model-2 Architecture.
model-2  arch

As shown in above model Servlet acts as Controller, JSP acts as View and JavaBean acts as Model. In this model, Controller receives requests which are transferred to data sources by View component and Model component. After the requests are serviced, JSP pages i.e. View component send responses back to client. These components can be described as follows:

  • Model: It represents data and business logic of the application that specifies how data is accessed and updated. Model is implemented by using JavaBeans. It has no concerns with the presentation logic.
  • View: It represents presentation logic. A View provides the Graphical User Interface (GUI) for model. It specifies how data should be presented to user in an understandable form. A user can interact with application through View and allows user to alter the data.
  • Controller: It acts as interface between view and model. It receives HTTP request. It controls all the Views associated with a Model. It receives requests from the client and delegates the responsibility for producing the next phase of user interface to view component.

MVC Advantages

  • This model is suitable for large applications.
  • It allows use of reusable software components to design the business logic.
  • It easy to maintain and test.

MVC Disadvantage

If we change the code in controller, we need to recompile the class and redeploy the application.

Previous Tutorial : Difference Between JSP and Servlet  || Next Tutorial : 

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*