How to start with Spring MVC

Reading Time: 3 minutes

In this blog I would like to introduce you to the Spring MVC framework, how it works with very detailed steps and at the end I will show How to create a Spring Controller class and view in a simple project.

What is Spring MVC?

It is a framework of Java that is generally used in order to develop web applications. It is built on a Model view controller pattern. Model-View-Controller(MVC) architecture provides the simplest way to develop flexible and loosely coupled web applications. All the primary features of the mainspring framework such as Inversion of control and dependency Injection are also implemented by Spring MVC.

(If you are unsure of what Spring or Spring Boot is, you might want to read What is Spring Framework?, first.)

Spring Web Model View Controller..

It comprises four main components as shown in the below figure.

Now let’s move further and understand the workflow .

How Spring MVC works?

  • All the incoming request are first received by the Dispatcher Servlet.
  • The Dispatcher Servlet then consults the Handler Mapping and forwards the request to the Controller.
  • The Controller calls the appropriate Service method and returns an object of ModelAndView to the Dispatcher Servlet.
  • The Dispatcher Servlet determines the view from the ModelandView object and passes the model object to the view.
  • The view then returns the results of the user.

Below diagram will make it clearer.

Steps to create a Spring MVC project.

  1. Either load the jar file(Spring core jar file, Spring web jar file, JSP+JSTL jar file) or add maven dependencies.
  2. Create a controller class
  3. The entry of the controller should be provided in the web.xml file.
  4. In the sperate XML file, define Bean.
  5. Output the message in a JSP file.
  6. Start the server and deploy the project.

Required jar files or Maven dependency

To run this example we need to load:

  • Spring Core jar files
  • Spring Web jar files
  • JSP + JSTL jar files (If you are using any other technology then load the corresponding jar files).

Download Link: Download all the jar files for spring including JSP and JSTL.


1?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
	id="WebApp_ID" version="3.1">


	<absolute-ordering />

	<!-- Spring MVC Configs -->

	<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->

	<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

	<!-- Step 3: Add support for component scanning -->
	<context:component-scan base-package="com.knoldus.springdemo1" />

	<!-- Step 4: Add support for conversion, formatting and validation support -->

	<!-- Step 5: Define Spring MVC view resolver -->
		<property name="prefix" value="/WEB-INF/view/" />
		<property name="suffix" value=".jsp" />


package com.knoldus.springdemo1.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

public class HomeController {
     public String showPage() {
		return "main-menu";


This is all that I wanted to talk about in this blog post.In the upcoming post I will talk more about Spring , Stay tuned.


Written by 

Anuradha Kumari is a Software consultant at Knoldus Inc. She is a tech enthusiast and likes to play with new technology and writing tech blogs.