Spring MVC BeanNameUrlHandlerMapping tutorial with example

What is BeanNameUrlHandlerMapping in spring

                Implementation of the HandlerMapping interface that map from URLs to beans with names that start with a slash ("/"), similar to how Struts maps URLs to action names.

    This is the default implementation used by the DispatcherServlet.

Example

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
           http://www.springframework.org/schema/util 
           http://www.springframework.org/schema/util/spring-util-3.0.xsd  
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

	<!-- ************************************************************* -->
	<!-- which handler mapping used here BeanNameUrlHandlerMapping -->

	<bean
		class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />

	<bean name="/beanNameUrlHandlerMapping.htm"
		class="com.candidjava.springmvc.BeanNameUrlHandlerMappingController" />

	<!-- ************************************************************* -->
	<!-- which resolver used here InternalResourceViewResolver -->

	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">

		<property name="prefix">
			<!-- location of jsp pages -->

			<value>/WEB-INF/pages/</value>
		</property>
		<!-- extension of pages -->

		<property name="suffix">
			<value>.jsp</value>
		</property>

	</bean>

	<!-- ************************************************************* -->

</beans>

Screenshot

                

                

Download 

Spring MVC hello world zip

Spring MVC hello world war



Comments


©candidjava.com