Form Processing in Spring MVC 3 using xml configuration

Previous tutorial illustrates, how form processing is done in spring mvc 3 using annotations. Its always been easy to work with annotations as they provides more flexibility for programmers and also provided a lot of options. In this tutorial we will learn how form processing can be done in spring mvc 3 using xml based configuration. It will be mandatory to read previous example to understand this tutorial in depth.

For converting our previous example of form processing into xml based configuration we have to change two things. These are as follows:

  1. First of all, we will change our controller class ( to extend SimpleFormController class provided in spring mvc jars and override some methods to handle form data. This will make our controller able to process form data.
  2. Then, we will change our configuration file (app-config.xml) to remove annotation based configuration and add our controller as a bean to handle url in mvc pattern.

As stated above, our controller class has to extend SimpleFormController class to process form using xml configuration. Following is the code in class :

package com.raistudies.controllers;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.raistudies.domain.User;

public class RegistrationController extends SimpleFormController{

    public RegistrationController(){

    protected ModelAndView onSubmit(Object command, BindException errors)
    throws Exception {
        ModelAndView mv = new ModelAndView();
            User user = (User)command;
            System.out.println("User values is : " + user);
            mv.addObject("USER", user);
        return mv;

The constructor of the controllers class sets User class command class and also the name of the model attribute as “USER”. It will tell spring mvc to create instance of User class and associate it with the form as model name “USER”. Our controller class overrides onSubmit method of SimpleFormController which will be called when form data will be submitted to the server. The method contains two parameters command object (object of User class) and BindException instance (contains information about errors).


We have to change our configuration file app-config.xml as follows to work with form processing :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

    <!-- Application Message Bundle -->
    <bean id="messageSource" class="">
        <property name="basename" value="/WEB-INF/messages" />
        <property name="cacheSeconds" value="3000" />

    <bean name="/registration.htm" class="com.raistudies.controllers.RegistrationController">
        <property name="formView" value="registration"/>
        <property name="successView" value="success"/>

    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>


Here you can see two new things happens. Our controllers has been registered as a bean and “name” attribute of tthe bean says the url on which the controller will be called. Two properties has been set to our controllers that are part of SimpleFormController. First is “formView”, it is the name of the view in which form in present, and another is “successView” which is the view to be show when processing of the form completed without any error.

You can download the example code from the following links :

Source : Download

Related Posts:

Leave a comment ?


  1. Hi,

    I download source code zip file. When I try to unzip it, it gives me error.

  2. really great..thanks a lot guys…ummah…:P

Leave a Comment Cancel reply

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>