Spring MVC 4 Example

Spring MVC 4 Example explains step by step example of configuring Spring MVC with eclipse

Spring version 4.0 provides full support for the latest Java 8 features.

Spring MVC is a popular Java Model-View-Contraller (MVC) framework. Basically spring is request based framework, which revolve around DispatcherServlet that dispatches the requests with the help of different lifecycle interfaces

Spring MVC have following important interfaces to handle a request during the execution phases of a HTTP request.

  • HandlerMapping
  • HandlerAdapter
  • Controller
  • View
  • ViewResolver
  • HandlerInterceptor
  • LocaleResolver
  • MultipartResolver

We can also use annotations like @RequestMapping,@Controller etc. for getting maximum flexibility


You can also read about implementing a REST service using Spring MVC below

Spring MVC 4 REST Example

Required Libraries
  1. JDK 6
  2. Eclipse 3.7
  3. Spring 4.0.5

Following jar must be in classpath

  1. commons-logging-1.1.1.jar
  2. spring-aop-4.0.5.RELEASE.jar
  3. spring-beans-4.0.5.RELEASE.jar
  4. spring-context-4.0.5.RELEASE.jar
  5. spring-core-4.0.5.RELEASE.jar
  6. spring-expression-4.0.5.RELEASE.jar
  7. spring-web-4.0.5.RELEASE.jar
  8. spring-webmvc-4.0.5.RELEASE.jar

You can see the project structure below

Spring MVC 4 Example


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>


<title>Spring MVC Form Handling</title>
<h2>Student Data Form</h2>
<form:form action="addStudent" method="POST">
				<td><form:label path="studId">Student ID:</form:label></td>
				<td><form:input path="studId"></form:input></td>
				<td><form:label path="name">StudentName :</form:label></td>
				<td><form:input path="name"></form:input></td>
				<td><form:label path="age">Student Age:</form:label></td>
				<td><form:input path="age"></form:input></td>
				<td colspan="2"><input type="submit" value="Submit" />

1 2 3 Next

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