【问题标题】:No mapping found for HTTP request with URI [/SaturdayTest/welcome] in DispatcherServlet with name 'spring-dispatcher'在名称为“spring-dispatcher”的 DispatcherServlet 中找不到带有 URI [/SaturdayTest/welcome] 的 HTTP 请求的映射
【发布时间】:2018-02-11 04:46:03
【问题描述】:

在名称为“spring-dispatcher”的 DispatcherServlet 中找不到带有 URI [/SaturdayTest/welcome] 的 HTTP 请求的映射

我找不到出错的地方。

HelloController.java

package com.prav.hellocontroller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController  {


@RequestMapping("/welcome")
public ModelAndView helloWorld() {
    ModelAndView model=new ModelAndView("HelloPage");
    model.addObject("msg","hello world");
    return model;
}    }

HelloPage.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>Insert title here</title>

</head>
<body>
<h1>${msg}<h1>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" 
version="3.1">

<display-name>SaturdayTest</display-name>

<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

spring-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.0.xsd">



<context:component-scan base-package="com.prav.hellocontroller">
</context:component-scan>

<bean id="viewResolver" 
class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>

检查了调度程序和映射,但名称相同。问题可能出在哪里。

【问题讨论】:

    标签: spring-mvc


    【解决方案1】:

    尝试添加:

    @RequestMapping("SaturdayTest")
    

    在您的控制器顶部。喜欢:

    @Controller
    @RequestMapping("SaturdayTest")
    public class HelloController  {
    

    告诉我这行得通。

    【讨论】:

    • 是的。删除我之前建议的@RequestMapping("SaturdayTest")。现在在您的方法上,提供@RequestMapping(""),即删除/欢迎。现在分享访问root的结果。
    【解决方案2】:

    @RequestMapping("/SaturdayTest/welcome") 尝试在您的方法上使用此注释

    【讨论】:

    • @karthy 堆栈跟踪?
    猜你喜欢
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多