Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Controller Interface example in Spring 2.5 MVC. Learn how to create and run the example.

The Controller Interface can be extended to create the controller in Spring 2.5 MVC.


Spring 4 Introduction and example Features of Spring Framework 5 How to make Spring web Login form? How to make Simple form in Spring web? Spring, Hibernate login and registration application Spring Framework Tutorial for beginners with examples Spring Framework for Apache Hadoop 2.3.0 GA released Spring Framework 4.1 GA is released with major features Why to use Spring Framework? Spring Framework 4.1 - First Release candidate available Spring IO Platform 1.0.0 Released Spring 4: Login Form using Spring MVC and Hibernate Example Spring 4 MVC Login form Example with source code Spring 4 MVC Hello World Example: Spring 4 MVC Tutorial will full source code Spring Web MVC Application Error:ClassNotFoundException: DispatcherServlet on deploying Features of Spring 4 Spring Framework 4.0 released Spring Framework 4: Spring Framework 4 Tutorials and Example Spring Integration 3.0 Release is released and available for download Spring Tutorial for Beginners Java Springs Framework Tutorial Spring Architecture Spring Framework Tutorials database spring registration form Spring Login Example Roseindia Spring Tutorial Spring Tutorial Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration

Controller Interface


Controller Interface implementation example in Spring 2.5 Web MVC framework:-

In this section we will see the example of Controller Interface in Spring MVC.

The Base portlet Controller interface (org.springframework.web.servlet.mvc.Controller) is a components that receives RenderRequest/RenderResponse and  also the ActionRequest/ActionResponse in the same was as a Portlet. The difference is that it also participate in an MVC workflow.

The implementation of org.springframework.web.servlet.mvc.Controller is reusable and threadsafe. The implementation class  is also capable of handling multiple.

In this tutorial we have created our controller by extending org.springframework.web.servlet.mvc.Controller interface. Here we will create a Spring 2.5 Web MVC example that used Controller Interface for control the user request.

Step 1:
Now we will create a index.jsp in project WebContent folder that contains a hyperlink "Controller" that linked "controllerinterface.html". When user click on this link a request will generate. The code of the index.jsp is:

<%@page contentType="text/html" pageEncoding="UTF-8"%>



<a href="controllerinterface.html">controller</a>



Step 2:

Now we will modify the web.xml for set the DispatcherServlet for this application and set the welcome file. The code of the web.xml is:

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

<web-app version="2.5"



xsi:schemaLocation="" >














Step 3:

Now we will create a dispatcher-servlet.xml file inside the project WEB-INF folder. The dispatcher-servlet.xml have the bean setting for viewResolver, urlMapping for assign the controller for the particular request. The code of the dispatcher-servlet.xml is:

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






<bean id="viewResolver"


<property name="prefix">



<property name="suffix">




<bean id="urlMapping"


<property name="interceptors">


<ref local="localeChangeInterceptor"/>



<property name="urlMap">


<entry key="/controllerinterface.html">

<ref bean="requestController"/>





<bean id="requestController" class=

<bean id="localeChangeInterceptor" class=

<property name="paramName" value="hl"/>


<bean id="localeResolver" class=


Step 4:

Now we will create a file inside of the project src folder. In this class we will implements "Controller" Interface for control the user request and return the ModelAndView as response. The application display that response for the user interface. The code of the is:

package net.roseindia.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller; 
public class RequestControllerInterface implements Controller   
  public ModelAndView handleRequest(HttpServletRequest request,
  HttpServletResponse responsethrows Exception {  
  ModelAndView modelandview = new ModelAndView("controllerinterface");
  modelandview.addObject("message""This is example of Controller Interface");
  return modelandview;

Step 5:

Now we will create a controllerinterface.jsp file inside the /WEB-INF/jsp/ folder. This jsp file contain code to display the response that will return by the controller. The code of the controllerinterface.jsp is:

<%@ taglib prefix="c" uri="" %>



<c:out value="${message}"/>



Step 6:

Now we will run this application and see the output like:

After click on this link request controller provide us message as a View like:

Download Code

Download this example code


Share on Google+Share on Google+

Controller Interface example in Spring 2.5 MVC. Learn how to create and run the example.

Posted on: August 27, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Controller Interface example in Spring 2.5 MVC. Learn how to create and run the example.  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
xuan toan
December 7, 2011
discuss about controller interface

How will we run controller interface?
Bryan Adams
May 10, 2012
Database programming with portlet

Please create new tutorial to insert data from form in to MySQL database.