Monday, May 21, 2012

dispatcherservlet does not wire model to view

I made a model from a controller and return to dispatcherservlet. It looks like there is no problem

in model since I double checked output by system.out.println. for viewname string, I double checked

an actual directory name which is "WEB-INF/views/hello.jsp".

but I believe dispatcher servlet does not adapt model to a view since browser does not displayed

a model value which should be displayed. It would be easier to understand what I am going through

if I put my code here. so... here is my code.




<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
<bean name="/hello" class="com.spring.toby.HelloController"/>
<bean id="HelloSpring" class="com.spring.toby.HelloSpring"></bean>

and controller java file

public class HelloController implements Controller{

@Autowired HelloSpring helloSpring;
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
// TODO Auto-generated method stub
String name = request.getParameter("name");
String msg = this.helloSpring.sayHello(name);
Map<String, Object> model = new HashMap<String, Object>();
model.put("msg", msg);
return new ModelAndView("WEB-INF/views/hello.jsp", model);

and bean file

public class HelloSpring {
public String sayHello(String name){
return "Hello " + name;

can anybody tell me what am I doing wrong? thanks in advance.

No comments:

Post a Comment