org.springframework.web.servlet.PageNotFound noHandlerFound;警告:在DispatcherServlet中找不到具有URI的HTTP请求的映射 [英] org.springframework.web.servlet.PageNotFound noHandlerFound; WARNING: No mapping found for HTTP request with URI in DispatcherServlet

查看:269
本文介绍了org.springframework.web.servlet.PageNotFound noHandlerFound;警告:在DispatcherServlet中找不到具有URI的HTTP请求的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了许多论坛和博客以获取答案,但没有任何有用的提示或建议.因此,如果有人可以在下面的问题上提供帮助,请帮忙.

I went through many forums and blogs to get the answer but couldn't get any useful tip or advice. So please if anybody can help in below issue it would be a great help.

尝试连接到http://localhost:8080/SpringApp/hello时出现以下警告和错误:

I am getting the below Warning and error when tried to connect to http://localhost:8080/SpringApp/hello :

INFO: Server startup in 6935 ms
Jul 19, 2014 11:15:42 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringApp/] in DispatcherServlet with name 'HelloWeb'
Jul 19, 2014 11:16:29 AM com.example.java.HelloController printHelloWorld
INFO: HelloController : printHelloWorld : ENTER
Jul 19, 2014 11:16:29 AM com.example.java.HelloController printHelloWorld
INFO: HelloController : printHelloWorld : EXIT
Jul 19, 2014 11:16:29 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringApp/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'HelloWeb'

因此,我在Tomcat中收到HTTP Status 404错误.

because of this I am getting HTTP Status 404 error in Tomcat.

下面提供了整个数据:

web.xml文件是:

The web.xml file is :

<display-name>Spring MVC Application</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

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

HelloWeb-Servlet.xml文件是:

The HelloWeb-Servlet.xml file is :

<?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.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd 
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.example.java"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>
<context:annotation-config/>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
</beans>

HelloController.java文件是:

The HelloController.java file is :

package com.example.java;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/hello")
public class HelloController {

    protected final Log logger = LogFactory.getLog(getClass());

    @RequestMapping(method=RequestMethod.GET)
    public String printHelloWorld(ModelMap model){
        logger.info("HelloController : printHelloWorld : ENTER");
        model.addAttribute("message", "Hello Sumit");
        logger.info("HelloController : printHelloWorld : EXIT");
        return "hello";
    }
}

推荐答案

在此处查看我的答案=

See My Answer Here= https://www.youtube.com/watch?v=-AtPAeSWz-o

以下内容对我有用.从上面的YouTube视频中可以看到,我已经对其进行了测试,并且可以正常运行.

The following worked for me. As you can see from the above YouTube video, I already tested it and it works.

目录结构:

确保您的目录结构与此匹配.

Make sure your directory structure matches this.

web.xml:

一些注意事项: <url-pattern>应该为<url-pattern>/<url-pattern>,因为当应用程序首次启动时,它会尝试连接到localhost:8080/YourAppName/,而不是localhost:8080/YourAppName/homePage.

A few things to note: The <url-pattern> should be <url-pattern>/<url-pattern> because when the app first starts up, it tries to connect to localhost:8080/YourAppName/ and not localhost:8080/YourAppName/homePage.

HelloController.java:

HelloController.java:

HelloWeb-servlet.xml

HelloWeb-servlet.xml

这篇关于org.springframework.web.servlet.PageNotFound noHandlerFound;警告:在DispatcherServlet中找不到具有URI的HTTP请求的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆