Controllers define application behavior. Controllers usually interpret user input and transform the user input into a model which will be represented to the user by the view. This Example will illustrate the concept in more details.

SpringexpController implements Controller interface which has handleRequest method and returns ModelAndView object. So programmer can override the functionality to return proper model and view. There are also some inbuilt controllers for different purposes in spring MVC framework.

 import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse ;


public class SpringexpController implements Controller {

  public ModelAndView handleRequest(HttpServletRequest request, 
      HttpServletResponse response) throws ServletException, IOException { 
    return new ModelAndView("WEB-INF/jsp/hello.jsp");

where hello.jsp is the view part:

<head><title>Example :: Spring Application</title></head>
<h1>Hello - Spring Application</h1>