Monday, June 30, 2008


Spring’s Dispatcher Servlet: test-servlet.xml You can break your xml files as you wish and can import all of them in test-servlet.xml so that during initialization of the application all of them will be loaded by the server as:

You have to give the url Mappings for different request types you want to handle by this servlet as:

The above syntax means, whatever request comes containing text will be handled by the bean loginController. Bean loginController can be defined there as

In this definition, bean id is the name of the bean which should be unique among all application xml files. Class signifies the location of the actual java file.

There are mainly two types of controllers which can process request in Spring –
SimpleFormController and MultiActionController. SimpleFormControllers are the controllers can handle only one type of request where as MultiActionControllers can handle different types of request.

Here loginController, which extends MultiActionController, is a MultiActionControllers. In a MultiActionController like loginController there are different methods to handle different requests. To map between them a property provided by Spring “methodNameResolver“ is there which tells the Controller which method is to be invoked for a given request. Here that method name resolver bean is “loginMethodNameResolver”.
It tells that if request type is “/” then go to “login” method in the loginController and for “/” request go to “formSubmit” method.

There are a lot of mappings of this kind which we have placed in other xml files and then all of them are imported in this test-servlet.xml. This type of break up will help in maintaining the changes in these files.

We have discussed mapping required for MultiActionController above. Following is the example of a SimpleFormController mapping:

This controller, which extends SimpleFormController, handles request “test/” only.Below is the example of a Controller, other than SimpleFormController and MultiAction Controller:

This “forgotPasswordController” handles only one request ””. This controller, which implements Controller Interface, only redirects the request to another controller or returns a simple model which contains nothing. We will see this Controller class later....