I go with Spring MVC as well.
You need to download Spring from here
To configure your web-app to use Spring add the following servlet to your web.xml
<web-app>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>*.form</url-pattern>
</servlet-mapping>
</web-app>
You then need to create your Spring config file /WEB-INF/spring-dispatcher-servlet.xml
Your first version of this file can be as simple as:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="com.acme.foo"/>
</beans>
Spring will then automatically detect classes annotated with @Controller
The Controller documentation describes how to write a controller, but here is a simple example:
package com.acme.foo;
import java.util.logging.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/person.form")
public class PersonController {
Logger logger = Logger.getAnonymousLogger();
@RequestMapping(method = RequestMethod.GET)
public String setupForm(ModelMap model) {
model.addAttribute("person", new Person());
return "details.jsp";
}
@RequestMapping(method = RequestMethod.POST)
public String processForm(@ModelAttribute("person") Person person) {
logger.info(person.getId());
logger.info(person.getName());
logger.info(person.getSurname());
return "success.jsp";
}
}
And the details.jsp
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<form:form commandName="person">
<table>
<tr>
<td>Id:</td>
<td><form:input path="id" /></td>
</tr>
<tr>
<td>Name:</td>
<td><form:input path="name" /></td>
</tr>
<tr>
<td>Surname:</td>
<td><form:input path="surname" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Save Changes" /></td>
</tr>
</table>
</form:form>
This is just the tip of the iceberg with regards to what Spring can do...
Hope this helps.