我看到了很多示例如何显示数据,这些数据是我定义并放入java控制器的,但我无法完成。代码在这里。将数据从控制器显示到jsp页面
@Controller
public class HomeController {
@RequestMapping({"/","/test"})
public String showHomePage(ModelMap model) {
String mes = "Here I am";
model.addAttribute("message",mes);
return "new";
}
}
new.jsp文件
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
${message}
</body>
</html>
当我开始在JSP页面只显示这样$ {文}
MVC-调度-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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
<context:component-scan base-package="ru.sbt"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
您必须直接命中控制器路径而不是JSP路径。 – 2015-03-19 10:46:31
我不明白你 – jenius 2015-03-19 10:47:21
我猜@RohitJain的意思是不访问/new.jsp,但/ test – bsiamionau 2015-03-19 10:48:03