This Spring MVC Tutorial explains Spring MVC application creation step by step. Whenever we start with any new technology, the first step we have to complete is – create a basic project structure and make that technology work. From detailed documentation of the technology, it becomes difficult to find out the first basic building blocks required. This tutorial takes the reader through the elementary steps to create a working Spring MVC project in Eclipse IDE and make it work on Tomcat. The technology involved are – Eclipse IDE (3.4.x), Tomcat (6.0), Java (1.5), Spring (2.5.5) and dependencies of Spring.

Create new Dynamic Web Project in Eclipse IDE:

Select appropriate target run time in second (New Dynamic Web Project) screen. Change the content directory and java source directory as shown. If you are not able to see the ‘Dynamic Web Project’ option in new project dialog box, then install updates for ‘Eclipse Platform’. On click of finish button, Eclipse will create a new project in the workspace.

 Spring MVC Tutorial

Spring MVC Tutorial

Spring MVC Tutorial

Adding Libraries for Spring MVC Tutorial:

Add following jars to the WEB-INF/lib directory.


Adding Libraries to Project:

Refresh Eclipse project and add the libraries to classpath as shown below.

Spring MVC Tutorial

Modifications to ‘web.xml‘:

Add following elements to the web.xml. Note – the servlet-name and url-pattern elements. Value of ‘url-pattern’ will be used in the url used to access pages. Value of element ‘servlet-name’ will be used to search the beans related to project in file ‘<servlet-name>-servlet.xml’.

            <servlet-name> SpringMVCTutorial</servlet-name>

Create ‘SpringMVCTutorial-servlet.xml’:

Create the file as below. This will contain the controller definitions. (There is no restriction that it should contain only controllers, but from maintenance point of view, it is better to group bean definitions in relevant files.

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
<bean name="/helloworld.htm" class="com.myorg.springmvctutorial.web.controller.HelloWorldController"/>

Create ‘‘:

This class contains controller implementation related to our HelloWorld functionality. This also integrates with Spring MVC framework through the class that it implements. This class uses simplest implementation of controller by using org.springframework.web.servlet.mvc.Controller class. More featured implementations are also available as a part of framework.

package com.myorg.springmvctutorial.web.controller;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HelloWorldController implements Controller {
  protected final Log logger = LogFactory.getLog(getClass());
  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {"Return View");
    return new ModelAndView("helloworld.jsp");

Create View helloworld.jsp:

This can be a simple jsp to show that our code is working fine.

<title>Hello World</title>
<h1>This is Spring MVC Tutorial</h1>
<p>Our Tutorial is successful.</p>

Add the Project to Tomcat Server:

Right click on SpringMVCTutorial project in eclipse and select ‘Run As à Run on Server’ option. Select the server and click finish. The application will be deployed on selected server.

Spring MVC Tutorial

Accessing the Spring MVC Tutorial Application:

Our application can be assessed using Url – http://localhost:8080/SpringMVCTutorial/helloworld.htm

Spring MVC Tutorial

Complete source code of the application (without libraries) can be found here.

Additional Articles You may find Interesting:

Spring MVC Tutorial With Command Object on Eclipse and Tomcat

Complete Hibernate Tutorial with Example

A Visit to Kailasa Temple at Ellora Caves

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS