简体   繁体   English

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

[英]org.springframework.web.servlet.DispatcherServlet noHandlerFound : Spring MVC

I am new to spring MVC. 我是春季MVC的新手。 I tried creating small hello world app but it is not running as expected. 我尝试创建小的Hello World应用程序,但未按预期运行。 I am always getting error org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI [/FitnessTracker/greeting.html] in DispatcherServlet with name 'fitTrackerServlet' 我总是收到错误org.springframework.web.servlet.DispatcherServlet noHandlerFound警告:在DispatcherServlet中,名称为“ fitTrackerServlet”的URI [/FitnessTracker/greeting.html]的HTTP请求找不到映射。

I know this error is very common and there are lots of links available on the google but none of them worked for me. 我知道这个错误非常普遍,Google上有很多可用的链接,但没有一个对我有用。 Any help would be appreciated. 任何帮助,将不胜感激。

Here is the code snippet 这是代码片段

HelloController.java HelloController.java

@Controller
public class HelloController {

@RequestMapping(value = "/greeting")    
public String sayHello(Model model) {
model.addAttribute("greeting","Hello World!!!!");
return "hello";
}}

hello.jsp hello.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>
Insert title here
</title>
</head>
<body>
<h1>
${greeting}
</h1>
</body>
</html>

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

<mvc:annotation-driven/>
<context:annotation-config/>
<context:component-scan base-package="com.firstspringmvc.controller"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
        p:prefix="/WEB-INF/jsp/" 
        p:suffix=".jsp"/>
</beans>

web.xml 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"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>Archetype Created Web Application</display-name>
    <servlet>
    <servlet-name>fitTrackerServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>fitTrackerServlet</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>  
</web-app>

Project Structure 项目结构 在此处输入图片说明

The URL /greeting does not have any .html at the end, so the servlet will not going to use the DispatcherServlet, because *.html pattern does not match the /greeting, and this will result in 404. URL /greeting末尾没有任何.html ,因此Servlet将不会使用DispatcherServlet,因为*.html模式与/ greeting不匹配,这将导致404。

Change your web.xml such: 更改您的web.xml,例如:

<servlet-mapping>
    <servlet-name>fitTrackerServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.springframework.web.servlet.DispatcherServlet noHandlerFound - org.springframework.web.servlet.DispatcherServlet noHandlerFound org.springframework.web.servlet.DispatcherServlet noHandlerFound用于基本的Spring示例 - org.springframework.web.servlet.DispatcherServlet noHandlerFound for basic spring example org.springframework.web.servlet.DispatcherServlet noHandlerFound 404错误响应 - org.springframework.web.servlet.DispatcherServlet noHandlerFound 404 error response 获取此 org.springframework.web.servlet.DispatcherServlet noHandlerFound 错误和警告:在 Spring MVC 中找不到 HTTP 请求 URI 的映射 - Getting this org.springframework.web.servlet.DispatcherServlet noHandlerFound error and WARNING: No mapping found for HTTP request URI in Spring MVC 如何解决Spring框架项目错误org.springframework.web.servlet.DispatcherServlet noHandlerFound? - How to resolve Spring framework project error org.springframework.web.servlet.DispatcherServlet noHandlerFound? 资源处理程序Spring异常:org.springframework.web.servlet.DispatcherServlet noHandlerFound - resource handler Spring exception: org.springframework.web.servlet.DispatcherServlet noHandlerFound org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI in DispatcherServlet with name - org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI in DispatcherServlet with name org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:GET /HelloWorld/helloweb 没有映射 - org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping for GET /HelloWorld/helloweb org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:GET /springMVCDemo/createAccount.html 没有映射 - org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping for GET /springMVCDemo/createAccount.html org.springframework.web.servlet.DispatcherServlet noHandlerFound(警告:未找到 HTTP 请求的映射) - org.springframework.web.servlet.DispatcherServlet noHandlerFound (WARNING: No mapping found for HTTP request)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM