Java Reference
In-Depth Information
matched with the name of the bean in the application context. Consider a request for the
following URL: http://www.myinsuranceportal.com/insuranceapp/createPolicy.do . This
request is intercepted by the dispatcher or front controller servlet, which would look for a
handler mapping registered in the Spring web application context. You can do this as
shown in Listing 3-6.
Listing 3-6. insurance-servlet.xml
<beans>
<bean name="beanNameUrlHandlerMapping"
class="org.springframework.web.servlet. å
handler.BeanNameUrlHandlerMapping"/>
<bean name="/createPolicy.do" class="com.apress.insuranceapp. å
web.CreatePolicyController"/>
</beans>
However, as stated earlier, this configuration is optional because
BeanNameUrlHandlerMapping is the default handler. In case no handler mapping is
found in the web application context, Spring MVC will create an instance of
BeanNameUrlHandlerMapping . Now that the handler mapping is detected, the front con-
troller will then look up a bean with the name / createPolicy.do in the Spring container.
It manages to resolve this as the CreatePolicyController command handler bean.
This handler mapping works relative to the servlet mapping and is not dependent on
the context path. Hence, changes in context path or servlet mapping will not require a
change in the bean configuration in the Spring container. However, it is possible to turn
on the use of full path by setting a boolean flag, alwaysUseFullPath , as shown in the con-
figuration in Listing 3-7.
Listing 3-7. insurance-servlet.xml
<beans>
<bean name="beanNameUrlHandlerMapping" class="org.springframework å
.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true" />
</bean>
</beans>
 
Search WWH ::




Custom Search