1. The org.springframework.web.servlet.handler.SimpleUrlHandlerMapping is one of the implementations of HandlerMapping interface.
  2. It locates the controller by matching the request URL’s with the key of the given properties or map.

Example:

  1. Create the Controller class.
  2. Configure controller class & SimpleUrlHandlerMapping in ds-servlet.xml file.
  3. Final project structure
  4. Deploy and Run the application in server.

Create the Controller class.

package com.java2learn.controller;

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 SaveEmployeeController implements Controller{

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("---Inside SaveEmployeeController::handleRequest method-----");
		return null;
	}
}

Configure controller class & SimpleUrlHandlerMapping in ds-servlet.xml file.

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

	<!-- Option-1 -->
	<!-- <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="mappings">
			<props>
				<prop key="saveEmployee.htm">saveEmp</prop>
			</props>
		</property>

	</bean> -->
	<!-- Option-2 -->
	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="urlMap">
			<map>
			 <entry key="saveEmployee.htm">
			   <ref local="saveEmp"/>
			 </entry>
			</map>
		</property>

	</bean>
	
	<bean id="saveEmp" class="com.java2learn.controller.SaveEmployeeController" />

</beans>

Final project structure.

Final-Project-Structure

Deploy and Run the application in server.

Output

Download the Project: SpringMVC-SimpleUrlHandlerMapping