Spring Framework

Spring Projects

Spring Project 1

adplus-dvertising
Handler Mapping in Spring MVC
Previous Home Next

Spring MVC provide the facility to handle between client request and DispatcherServlet , the DispatcherServlet provide the facility to Handler Mapping Object to map between Request and Handling Object. A Handler Mapping provide the the facility to Client's Url has to be mapped to the Handlers.

Type of Handler Mapping in Spring

The spring MVC provide the four types of handler which are map in the spring mapping file which are following:

  1. BeanNameUrlHandlerMapping
  2. CommonsPathMapHandlerMapping
  3. ControllerClassNameHandlerMapping
  4. SimpleUrlHandlerMapping

BeanNameUrlHandlerMapping: The BeanNameUrlHandlerMapping provide the facility to map the simple handler which are come from client bean object. This handler map in following types in spring configuration file:

<beans ...>
<bean 
class="org.springframework.web.servlet.
handler.BeanNameUrlHandlerMapping"/>
<bean name="/welcome.bean" 
class="r4r.co.controller.WelcomeController" />
<bean name="/login.bean" 
class="r4r.co.controller.LoginController" />
<bean name="/registeration.bean" 
class="r4r.co.controller.RegisterationController" />
</beans>

CommonsPathMapHandlerMapping: The CommonsPathMapHandlerMapping provide the facility to the name of URL which are mapped to the controller source file for example if we are to map 'loginPage','registerationPage' and 'welcomePage' to Controllers name LoginController, RegisterationController and WelcomeController,then the mapping information allocate in meta-data in the source files inside the Javadoc comments. This handler mapping example which are following:

<beans>

<bean id="metaHandlerMapping" 
class="org.springframework.web.servlet.handler.
metadata.CommonsPathMapHandlerMapping"/>

</beans>

ControllerClassNameHandlerMapping: This handler provide the facility to handle the more then one Handler Mapping, the Controller name using directly from the Url itself with some modifications. This handler mapping are show in the following:

<beans ...>
<bean 
class="org.springframework.web.servlet.mvc.
support.ControllerClassNameHandlerMapping" />
<bean class="r4r.co.controller.WelcomeController" />
<bean class="r4r.co.controller.HelloGuestController" />
</beans>

SimpleUrlHandlerMapping: This handler provide the facility to handle more then one handler map directly to the Client Request to some Controller object. Example of this handler which are following:

<beans ...>
<bean class="org.springframework.web.servlet.
handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/welcome.bean">welcomeController</prop>
<prop key="/login.bean">loginController</prop>
<prop key="/registeration.bean">registerationController
</prop>
</props>
</property>
</bean>
<bean id="welcomeController" 
class="r4r.co.controller.WelcomeController" />
<bean id="loginController" 
class="r4r.co.controller.LoginController" />
<bean id="RegisterationController" 
class="r4r.co.controller.RegisterationController" />
</beans>
  1. Example of BeanNameUrlHandlerMapping in Spring MVC
  2. Example of ControllerClassNameHandlerMapping in Spring MVC
  3. Example of SimpleUrlHandlerMapping in Spring MVC
Previous Home Next