Spring Framework

Spring Projects

Spring Project 1

Spring MVC Implementation
Previous Home Next

Introduction: In Spring MVC implementation the controller is an application component. Which is responsible for processing the request. It does not controlled the workflow of request processing as done by struts controller.

Workflow of request is controlled by front controller which is implemented by servlet name "DispatcherServlet" is provides a single entry point in to the application.

Model View Controller (MVC):

Model: Model component represent a data for spring MVC usually a map of model object is used as Model component.

View: View is a generic component of the framework which is responsible for presenting data to the end user. Multiple implementation of view are provided the framework to support different presentation technique.

Controller: Controller component provide the facility to change the state and flow the data. Controller component is responsible for the controlled the workflow of the web application in the spring framework.


How can we implement spring MVC:

Following steps are required to used spring MVC implementation:

Step 1: First select the web project in our IDE and add the capability of spring framework (it means that add the jar file). The following jar file are add before implement the spring MVC application.

  1. Spring 2.5 core Library
  2. Spring 2.5 web Library


Step 2: Servlet entry is to be made in web.xml file for DispatcherServlet class.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

step 3: Define in xml file to specified a mapping requested url and controller of spring application. This file is conventionally name as follows



step 4: If DispatcherServlet is assign "frontController" name in web.xml then this file must be named as"frontController-servlet.xml"

step 5: The file "frontController-servlet.xml" used the bean element to mapped request url and controller Class

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

<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<property name="url">
<property name="username">
<property name="password">

<bean id="jdbcTemp" class="org.springframework.jdbc.core.JdbcTemplate">
<ref local="datasource"/>

<bean id="loginModel" class="org.r4r.LoginModel"/>

step 6: Define controller class, Controller is a subclass of AbstractController class. AbstractController class provides an abstract method name

handleRequestInternal(HttpServletRequest request,HttpServletResponse response); 

which is invoked each time a request of the controller received. This method returned a ModelAndView object.

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Comment / Feedback: