Monday, August 13, 2007

Spring Controller interface

Simple Controller (

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class HomeController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return new ModelAndView("home", "message", greeting);
private String greeting;
public void setGreeting(String greeting) {
this.greeting = greeting;

applicationContext.xml should include :

<bean name="homeControler" class="">
<property name="greeting">
<value>Welcome to Book Store!</value>

Also the view resolver and url mapping should be specified in this xml file.

You can access the message variable in home.jsp as :


No comments:

Post a Comment