0

使用 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;
}

测试.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>
4

1 回答 1

0

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

于 2018-02-25T13:41:12.077 回答