spring mvc hello world example step by step

spring mvc hello world example step by step

Spring hello world…!!!

Step 1: 

Create a dynamic web project named “JavadomainSpringMVC”.

Step 2: Download and add the below mentioned spring jar files to lib folder which is in WebContent/WEB-INF/lib.

Required Spring jar files:
1. commons-logging-1.0.4
2. jstl-1.2
3. org.springframework.asm-3.1.0.RELEASE
4. org.springframework.beans-3.1.0.RELEASE
5. org.springframework.context-3.1.0.RELEASE
6. org.springframework.core-3.1.0.RELEASE
7. org.springframework.expression-3.1.0.RELEASE
8. org.springframework.web.servlet-3.1.0.RELEASE
9. org.springframework.web-3.1.0.RELEASE
10. spring-web-3.2.1.RELEASE

Download all jar files

Step 2:

Create a package named “in.javadomain.spring.controller” under src.

Creating package

Step 3:

Create a java class (here controller) named “BlogAuthorController” and paste the below code,

package in.javadomain.spring.controller;

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

public class BlogAuthorController {

public ModelAndView Blog() {

String message = "Javadomain.in provides lot of programming solutions and tutorials";
return new ModelAndView("javadomain", "blogInformation",message);</pre>

public ModelAndView Author() {

String message = "I am Naveen author of Javadomain.in";
return new ModelAndView("author", "authorInformation",message);</pre>

 Step 4:

Create a web.xml (deployment descriptor) under WebContent/WEB-INF folder and paste the below code

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

Step 5: Create a file named “JavadomainSpring-servlet.xml” (Dispatcher servlet)  and copy the below code,

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

        base-package="in.javadomain.spring.controller" />

    <bean id="viewResolver"
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/jsp/" />
        <property name="suffix" value=".jsp" />


Step 6: Create a file named “index.jsp” and copy the below code,

    <a href="javadomain.html">About Javadomain</a> <br><br>
     <a href="author.html">About Author</a>

Step 7:  Create a folder named “jsp” under WebContent and create a “javadomain.jsp” and “author.jsp” under “jsp” folder that we have created as like below,

author.jsp and javadomain.jsp

Step 8: Copy the below code to “author.jsp” file,


and copy the below code to “javadomain.jsp” file,


Step 9: Project structure looks like this,

project structure MVC hello world

Step 10: Now run the “index.jsp” file and click the link to see the outputs as like below,

Spring hello world output

Javadomain output

author output

Download the Project:
Spring MVC Hello World Package


Download the Spring MVC Hello world Package for Spring version 4:

Spring 4 MVC Hello World Package with all the required Jars




1. Once the url entered, the request will go to deployment descriptor (web.xml).
2. From the web.xml the request will be moved to dispatcher servlet (app-string.xml) file.
3. From the dispatcher servlet request will be moved to controller.
4. Controller will return the object to the view.
5. View will display the response for the request.

1,148 total views, 2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.