每当尝试在浏览器中连接到我的 Controller 时,我都会收到空白页面。请求映射是正确的,我返回了正确的 jsp,但除了空白屏幕之外,浏览器上没有显示任何内容。
它似乎正在到达 Controller ,并且我没有收到任何错误。
调度程序 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>
Controller
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>
最佳答案
您正在发送 grettings
模型对象,但正在打印${greeting}
。拼写不匹配。
关于java - 尝试访问返回 jsp 页面的 Controller 时出现空白页。一切都链接得很好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29774353/