Create Simple Project Spring MVC

1.) Create your Web Spring MVC Project, I’ll Show how to create using maven command for Windows User :

  • Before that make sure you have download and install:
  • java 8 or 7
  • Eclipse Mars
  • Tomcat 8

open CMD , and your folder  project , add this command and Enter :

mvn archetype:generate -DgroupId=<Your domain name> -DartifactId=<Project Name> -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

  • My Example: mvn archetype:generate -DgroupId=com.fndong -DartifactId=HelloSpringMVC -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
  • If you check the result is : Build Success , its mean you are successfully create new web app project using maven.
  • Some info: If failed to download lib to local repository because your office Network PC have the proxy setting. To solve it by setting the setting.xml file and add in .m2 folder. You can get the setting.xml from maven Apache installer,  Enable proxy setting :

<!– proxy
| Specification for one proxy, to be used in connecting to the network.


2.) Then , Import the HelloSpringMVC  maven project to your Eclipse Mars.

2.1) after importing , check your Build Path , some folde java are missing “src\main\java” and “src\test\java“.

  • remove the missing , and Add new “Add Folder..


3) Then Check the Error.


  • This is occurred because missing HttpServlet, you can add dependencies or using Tomcat Server  lib Servlet, by add the project to Target Runtimes :   Target Runtimes > select Apache Tomcat 8
  • Then The Error will disappeared.

4) Create web.xml , Map Spring MVC in /Webapp/WEB-INF/web.xml file.

  • In web.xml will map org.springframework.web.servlet.DispatcherServlet with url pattern  <url-pattern>*.htm</url-pattern>.
  • The Name of servlet in <servlet-name> tag in web.xml. Once the DispatcherServlet is initialized, it will looks for a file name [servlet-name]-servlet.xml  in WEB-INF folder of web application.

<?xml version=1.0 encoding=UTF-8?><web-app version=3.0 xmlns= xmlns:xsi= xsi:schemaLocation=> <display-name>Archetype Created Web Application</display-name>
<display-name>Archetype Created Web Application</display-name>




5.) Create Spring Configuration Bean file. /Webapp/WEB-INF/mvc-dispatcher-servlet.xml

  • Description About mvc-dispatcher-servlet.xml: , mvc-dispatcher-servlet.xml configuration file, we have defined a tag <context:component-scan> . This will allow Spring to load all the components from package com.fndong.controller  and all its child packages.

<beans xmlns= xmlns:context= xmlns:xsi= xsi:schemaLocation=>

<context:component-scan base-package=”com.fndong.controller” />

<property name=”prefix“>
<property name=”suffix“>

6.) Add Spring dependency in pom.xml.



<!– Spring dependencies –>



7.) Make sure to add Maven dependencies, right click project > properties > Deployment Assembly > Add > Maven Dependencies


8.) Update your index.jsp , which one button will have action to go to others page – Hello.jsp.

<!DOCTYPE html>

$(“p”).css(“background-color“, “yellow“);
$(“p”).css(“background-color“, “lightgray“);

.important {
font-weight: bold;
font-size: xx-large;

.blue {
color: blue;
<p><a href=”hello.htm“>Say Hello…</a></p></body>

9.) Hello.jsp ( for the second Page)

<%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” ““>
text/javascript” src=”jquery-1.2.6.min.js“>
<title>Good Job</title>
</head> <body> <center>
<h2>Great To see You Man, Good Job</h2>

10.) Java Controller ,

package com.fndong.controller;

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

public class HelloController {
String message = “Good Job Man !“;

public ModelAndView showMessage() {
return new ModelAndView(“hello“, “message“, message);

11.) OUTPUT, Add to Server (deploy) Tomcat 8, then start the server.


12) click Say Hello …,


13.) Full Source Code Project :


14.) Download This Project from my GitHub by click Download button below:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s