Spring MVC — Controller Class Name Handler Mapping | Code Factory

Code Factory
3 min readJan 28, 2021


Donate : Link

WordPress Blog : Link

Applications… : Link

Spring Tutorial Index Page: Link

  • ControllerClassNameUrlHandlerMapping class automatically it will find out controller class based on your requested url pattern. The ControllerClassNameHandlerMapping class is the convention-based handler mapping class, which maps the URL request(s) to the name of the controllers mentioned in the configuration file. This class takes the Controller names and converts them to lower case with a leading “/”. For example − HelloController maps to “/hello*” URL. So in this case we don’t require to use name attribute in <bean> tag.

Create Java Project

  • Open Eclipse
  • Go to File -> New -> Dynamic Web Project
  • Create MVC-HelloWorld-ControllerClassName project
  • Right click on project -> Build Path -> Configure Build Path -> Libraries tab -> Add External JARs (Used 2.X jars)
    - commons-logging-X.X.jar
    - spring-beans-X.X.X.jar
    - spring-context-X.X.X.jar
    - spring-core-X.X.X.jar
    - spring-web-X.X.X.jar
    - spring-webmvc-X.X.X.jar
  • Also add these jars in WEB-INF/lib folder for runtime.
  • * You can find dtd information from spring-beans-X.X.X.jar -> org -> springframework -> beans -> factory -> xml -> spring-beans.dtd (line no 36 & 37)


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"



<!-- default -->


<beans> <!-- controller class name handler mapping -->
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
<!-- controller -->
<bean id="hc" class="com.codeFactory.controller.HelloController" />
<!-- view resolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />


package com.codeFactory.controller;import java.util.HashMap;
import java.util.Map;
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 HelloController implements Controller { @Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String name = request.getParameter("name");
Map map = new HashMap();
map.put("type", "ControllerClassNameHandlerMapping");
map.put("message", "Hello " + name);

ModelAndView modelAndView = new ModelAndView("success", map);
return modelAndView;


<h2>Hello World</h2>
<form action="./hello.code">
Name: <input type="text" name="name">
<input type="submit" value="Submit">


<p>Handler Mapping Type : ${type}</p>