Spring MVC 错误:org.springframework.web.servlet.DispatcherServlet noHandlerFound

乔金德·帕万

我创建了一个简单的 Spring MVC 项目来显示“Hello World”,并且工作正常。现在,我想添加一些 css 属性。我在 WebContent 中创建了一个 css 文件夹,并在其中添加了一个 css 文件,并在我的调度程序 servlet 中添加了以下行:

<mvc:resources mapping="/css/**" location="/css/" />

现在我在控制台上遇到以下错误:

org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringTest/] 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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>SpringGradle</display-name>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>/WEB-INF/spring-servlet.xml</param-value>         
       </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>        
    </servlet-mapping>  
</web-app>

这是我的 Dispatcher servlet:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    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.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.pawan.controller" />
    <mvc:resources mapping="/css/**" location="/css/" />

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

</beans>

和 JSP 文件:

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<spring:url value="/css/myStyleCss.css" var="myStyleCss" />
<link href="${myStyleCss}" rel="stylesheet" />

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<body>
 <h2 class="test">Welcome</h2><br>
<h3>${message}</h3>
</body>
</html>

控制器类:

package com.pawan.controller;

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

@Controller
public class LoginController {

    @RequestMapping("/")
    public ModelAndView login() {

        ModelAndView model = new ModelAndView("home");
        model.addObject("message", "Hello !!! First Spring Program");
        return model;
    }
}

请帮助我清除我的概念。

乔金德·帕万

已解决:我的调度程序 servlet 中缺少以下行:

<mvc:annotation-driven />

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

org.springframework.web.servlet.DispatcherServlet noHandlerFound

错误[org.springframework.web.servlet.DispatcherServlet]

org.springframework.web.servlet.PageNotFound noHandlerFound; 警告:在DispatcherServlet中找不到具有URI的HTTP请求的映射

从Spring 3.0迁移到Spring 3.1时org.springframework.web.servlet.DispatcherServlet错误

Spring Maven DispatcherServlet noHandlerFound

org.springframework.web.servlet.PageNotFound noHandlerFound未找到具有URI的HTTP请求的映射

org.springframework.web.servlet.PageNotFound noHandlerFound-未找到具有URI的HTTP请求的映射

org.springframework.web.servlet.PageNotFound noHandlerFound-发送参数时出错

获取.servlet.DispatcherServlet noHandlerFound

Spring Boot 1.5.3 NoSuchMethodError:org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.getResponseStatus()

如何在Spring MVC中解析org.springframework.web.servlet.view.InternalResourceViewResolver

问题-java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

Tomcat,java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

VSCODE:java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

找不到 org.springframework.web.servlet.mvc.SimpleFormController

org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleHttpRequestMethodNotSupported

java.lang.ClassNotFoundException:com.springframework.web.servlet.DispatcherServlet

在 Spring MVC 中出现错误 Missing artifact spring-web:org.springframework

尝试设置Spring Web Service时出错NoSuchMethodError:org.springframework.web.servlet.FrameworkServlet。<init>

创建bean'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#1'时出错

Spring cloud Feign:找不到适合响应类型的HttpMessageConverter [class org.springframework.web.servlet.ModelAndView]

严重:错误配置类 [org.springframework.web.context.ContextLoaderListener] NoClassDefFoundError: javax/servlet/ServletContextListener

Spring MVC Webapp-java.lang.ClassNotFoundException:org.springframework.web.context.support.ServletRequestHandledEvent

Spring Boot异常:无法打开ServletContext资源[/WEB-INF/dispatcherServlet-servlet.xml]

错误:org.springframework.jdbc.BadSqlGrammarException:StatementCallback; 错误的SQL语法Java Spring MVC

org.springframework.beans.factory.UnsatisfiedDependencyException 使用 Spring web-mvc 5.0.1.RELEASE 和 Hibernate 5.2.15.Final 时

错误org.springframework.web.HttpMediaTypeNotSupportedException

Spring MVC 初学者。noClassDefDefinition org/springframework/util/MimeType

Spring MVC项目中的org.springframework.beans.factory.BeanCreationException