每当尝试在浏览器中连接到我的控制器时,我都会得到一个空白页面。请求映射是正确的,我正在返回正确的jsp,但除了空白屏幕之外,浏览器上没有显示任何内容。
它似乎到达了控制器,我没有错误。
Dispatcher servlet
<?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-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.ProjectOne" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
控制器
package com.ProjectOne.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* @author SLavelle
*
*/
@Controller
public class WelcomeController {
@RequestMapping("/")
public ModelAndView Home() {
ModelAndView modelAndView = new ModelAndView("homepage");
modelAndView.addObject("greetings", "Welcome to ProjectOne!");
return modelAndView;
}
}
JSP
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ProjectOne</title>
<link href="${pageContext.request.contextPath}/resources/css/welcome.css" rel="stylesheet" >
<h1>${greeting}</h1>
<br>
</head>
<body>
</body>
</html>
答案 0 :(得分:1)
您正在发送grettings
模型对象,但您正在打印${greeting}
。拼写不匹配。
答案 1 :(得分:0)
您的<H1> and <br>
标记应位于JSP页面的正文中...
<head>
<body>
<h1>${greeting}</h1>
</body>
HTML正文标记中的所有内容都显示在屏幕上。