我看到了很多示例如何顯示數據,這些數據是我定義並放入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