Java Reference
In-Depth Information
SimpleUrlHandlerMapping
The BeanNameUrlHandlerMapping class does not support wildcards to resolve a request
URL to a bean name. Let's assume you want the UpdatePolicyController to handle two
requests: /createPolicy.do and /updatePolicy.do . With BeanNameUrlHanderMapping , you will
need to configure two <bean /> entries. This is redundant, and configuration can be sim-
plified with Apache Ant-style wildcard path mapping with the SimpleUrlHandlerMapping
class. Since this is not the default handler mapping, it has to be explicitly configured in
the Spring configuration file, as shown in Listing 3-8.
Listing 3-8. insurance-servlet.xml
<beans>
<bean name="simpleUrlHandlerMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/*Policy.do">updatePolicyController</prop>
</props>
</property>
</bean>
<bean name="updatePolicyController" class="com.apress.insuranceapp å
.web.UpdatePolicyController"/>
</beans>
As shown in Listing 3-8, the controllers are configured just like any other bean in the
Spring container. The mappings property of the handler mapping is very important. It is
wired using a java.util.Properties object. Each key of this object is a URL pattern. The
key for the updatePolicyController is the URL pattern: /*Policy.do . It uses the * wildcard.
This means any request URL ending with Policy.do will be handled by this page con-
troller.
Note that once this handler mapping is detected by the dispatcher servlet, it no
longer needs to create the default bean handler mapping instance.
 
Search WWH ::




Custom Search