我从控制器制作了一个模型并返回到 dispatcherservlet。看起来没有问题
在模型中,因为我仔细检查了 system.out.println 的输出。对于 viewname 字符串,我仔细检查了
一个实际的目录名称,即“WEB-INF/views/hello.jsp”。
但我相信调度程序 servlet 不会使模型适应视图,因为浏览器不显示
应显示的模型值。更容易理解我正在经历的事情
如果我把我的代码放在这里。所以...这是我的代码。
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/spring-servlet.xml
</param-value>
</context-param>
spring-servlet.xml
<?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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
>
<context:annotation-config/>
<bean name="/hello" class="com.spring.toby.HelloController"/>
<bean id="HelloSpring" class="com.spring.toby.HelloSpring"></bean>
</beans>
和控制器java文件
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);
System.out.println(msg);
Map<String, Object> model = new HashMap<String, Object>();
model.put("msg", msg);
return new ModelAndView("WEB-INF/views/hello.jsp", model);
}
}
和 bean 文件
public class HelloSpring {
public String sayHello(String name){
return "Hello " + name;
}
}
和jsp文件
</head>
<body>
<div><h1>Testing</h1></div>
${message}
</body>
谁能告诉我我做错了什么?提前致谢。