【问题标题】:Spring mvc ModelAndView occur 404 ErrorSpring mvc ModelAndView 出现 404 错误
【发布时间】:2018-02-25 12:12:02
【问题描述】:

使用 OSX、Spring mvc 4、intellij

我想使用ModelAndView。 当我进入 server/board/showArticleList 时,它显示 404 错误,如下所示。 并且服务器没有显示任何错误。

浏览器中的错误消息

Type Status Report

Message /WEB-INF/views/board/showArticleList.jsp

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

控制器

@RequestMapping(value="/board/showArticleList")
public ModelAndView handleRequest(HttpServletRequest arg0,
                                  HttpServletResponse arg1) throws Exception {

    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setView("test");
    modelAndView.addObject("title", "this is title");

    return modelAndView;
}

test.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>testPage</title>
</head>
<body>
    ${title}
</body>
</html>

调度程序-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-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="Controller"></context:component-scan>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

</beans>

【问题讨论】:

    标签: spring jsp spring-mvc modelandview


    【解决方案1】:

    setview 和 RequestMapping 中的视图名称不匹配,因此 Dispatcher Servlet 无法解析视图。

    【讨论】:

    • 如何绕过它而不改变映射?
    • 只需更改jsp文件名以匹配映射
    猜你喜欢
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 2010-11-05
    • 2017-02-24
    • 1970-01-01
    • 2017-06-18
    相关资源
    最近更新 更多