Using Handler Mappings

Before we can talk about all the exciting components of the Spring MVC framework, we must take the time to explain how URL mapping works in Spring. You need the URL mapping to tell Spring which controller to invoke for the specific request. Even though it sounds complicated, it is not too difficult and can be done easily in the Spring application context file.

Spring uses HandlerMapping implementations to identify the controller to invoke and comes with the implementations of HandlerMapping shown in Table 17-1.

Table 17-1: HandlerMapping Implementations

HandlerMapping

Description

BeanNameUrlHandlerMapping

The bean name is identified by the URL. If the URL is /product/index.html, the controller id that handles this mapping would have to be set to /product/index.html. This mapping is useful for smaller applications because it does not support wildcards in the requests.

SimpleUrlHandlerMapping

This handler mapping allows you to specify the requests (using full names and wildcards) that specify which controller is going to handle the request.

We are not going to use the BeanNameUrlHandlerMapping in our application; instead, we start using the SimpleUrlHandlerMapping. An example of BeanNameUrlHandlerMapping is shown in Chapter 16.



Pro Spring
Pro Spring
ISBN: 1590594614
EAN: 2147483647
Year: 2006
Pages: 189

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net