If you haven't done so already, check out the Spring MVC step-by-step tutorial.
Spring MVC tutorial
This will give you an excellent example of how to construct a simple Spring MVC web application.
The only problem is it doesn't cover using Annotations in Spring 2.5+. You'll have to either wait for the Spring 3.0 MVC tutorial to release, or dig through the official Spring documentation yourself to learn how to use it.
EDIT
Here's an example involving controlling a form:
Note: Spring 3.0.0
Your controller:
@Controller
@RequestMapping("/blog.htm")
public class BlogController{
// Service layer class
private final BlogManager blogManager;
// Inject the blog manager into the constructor automatically
@Autowired
public BlogController(BlogManager blogManager){
this.blogManager = blogManager
}
// Set up the form and return the logical view name
@RequestMapping(method=RequestMethod.GET)
public String setupForm(ModelMap model){
model.addAttribute(new EntryForm());
return "addBlog";
}
// Executed when posting the form
@RequestMapping(method=RequestMethod.POST)
public String addBlog(@ModelAttribute("entryForm")EntryForm entryForm){
// Read the entry form command object from the form
String text = entryForm.getText();
// Call your service method
blogManager.addEntry(text);
// Usually redirect to a new logical view name
return "redirect:/homepage";
}
}
Form command object:
public class EntryForm{
private String text;
// setters and getters for text
}
Here is your service layer class
public class BlogManager{
private final BlogDAO blogDAO;
@Autowired
public BlogManager(BlogDAO blogDAO){
this.blogDAO = blogDAO;
}
public void addEntry(String text){
int blogID = 100; // simple example id for a blog
Blog blog = blogDAO.findById(blogID);
blog.addEntry(text);
blogDAO.update(blog);
}
}
And now you update your spring.xml file to tie it all together
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- Scan for spring annotations -->
<context:component-scan base-package="test.package"/>
<!-- defined in the xml file and autowired into controllers and services -->
<bean id="blogManager" class="test.package.BlogManager" />
<bean id="blogDAO" class="test.package.dao.BlogDAO" />
<!-- Resolves logical view names to jsps in /WEB-INF/jsp folder -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>