Simple Controller (HomeController.java)
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="com.springinaction.training.mvc.HomeController">
<property name="greeting">
<value>Welcome to Book Store!</value>
</property>
</bean>
Also the view resolver and url mapping should be specified in this xml file.
You can access the message variable in home.jsp as :
${message}
Monday, August 13, 2007
Spring Controller interface
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment