java - 警告 : No mapping found for HTTP request with URI [/Spring3MVC/hello. html] 在 DispatcherServlet 中,名称为 'spring'

标签 java spring spring-mvc

为什么会发生这种情况。

"WARNING: No mapping found for HTTP request with URI [/Spring3MVC/hello.html] in DispatcherServlet with name 'spring' "

我的 web.xml 是

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <display-name>Spring3MVC</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
</web-app>

spring.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:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="net.viralpatel.spring3.controller"/>

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>
</beans>

index.jsp 是

<!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>
    <a href="hello.html">Say Hello</a>
</body>
</html>

hello.jsp 是

<html>
<body>
    <h1>Message : ${message}</h1>   
</body>
</html>

HelloWorldController.java 是

package net.viralpatel.spring3.controller;

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

@Controller
public class HelloWorldController {

    @RequestMapping("/hello")
    public ModelAndView helloWorld() {

        String message = "Hello World, Spring 3.0!";
        return new ModelAndView("hello", "message", message);
    }
}

为什么上面的警告出现但没有击中 Controller 。

org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/Spring3MVC/hello.html] in DispatcherServlet with name 'spring'.

最佳答案

尝试添加<mvc:annotation-driven /> .

关于java - 警告 : No mapping found for HTTP request with URI [/Spring3MVC/hello. html] 在 DispatcherServlet 中,名称为 'spring',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29092879/

相关文章:

java - android-bitmap 低质量问题

java - 无法通过 Jenkins 运行 Rhapsody 应用程序

javascript - 解析 JSON 并使用 jQuery mobile 中的数据扩展 ListView

java - Spring Boot webflux 仅返回 401 和 403

java - Hibernate 查询 where 子句中的 list<t>

java - jsp表单发送数据到servlet而不改变页面

java - 连接 JDBC MySQL 时出现异常

java - Spring Boot - 处理 JSON 或 HTML 的错误 Controller

java - 检索用户所需的最低 SpringSecurity 配置

java - 如何使用异步 API 在 java 中发送电子邮件