【问题标题】:Blank page when trying to go to a controller that returns a jsp page. it all links fine尝试转到返回 jsp 页面的控制器时出现空白页面。一切都很好
【发布时间】:2015-04-21 13:57:06
【问题描述】:

每当尝试在浏览器中连接到我的控制器时,我都会得到一个空白页面。请求映射是正确的,我正在返回正确的 jsp,但除了空白屏幕之外,浏览器上没有显示任何内容。

它似乎到达了控制器,我没有收到任何错误。

调度程序小服务程序

   <?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>

【问题讨论】:

  • 需要更多信息......就像你到目前为止所做的那样
  • 我创建了一个返回模型和视图的控制器。视图是一个jsp。
  • 请附上您的 dispatcher-servlet.xml 、控制器和 jsp 页面代码以及您的问题
  • 你能调试控制器吗,它应该在哪里到达控制器?你应该添加一些你的 config/controller/jsp 的代码片段,否则它会在我们的黑暗中寻找。
  • 编辑了我的问题:)

标签: java spring jsp controller


【解决方案1】:

您正在发送grettings 模型对象,但您正在打印${greeting}。拼写不匹配。

【讨论】:

  • 啊,好吧,所以拼写不匹配,我正在发送问候语,但打印问候语时没有(s)欢呼。
【解决方案2】:

你的&lt;H1&gt; and &lt;br&gt;标签应该在你的JSP页面的正文中……

<head>
<body>
<h1>${greeting}</h1>
</body>

HTML body 标签中的所有内容都显示在屏幕上。

【讨论】:

    猜你喜欢
    • 2012-12-20
    • 1970-01-01
    • 2021-04-14
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多