No mapping found for HTTP request with URI [/HelloWeb/] in DispatcherServlet with name 'HelloWeb

Posted 沧海一滴

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了No mapping found for HTTP request with URI [/HelloWeb/] in DispatcherServlet with name 'HelloWeb相关的知识,希望对你有一定的参考价值。

I‘m learning the Spring Framework, and I‘m doing the HelloWeb tutorial on tutorialspoint, and I can‘t get it working. I‘m using Spring MVC 4.0, and I‘m deploying my app from Netbeans 8.0 to a Glassfish Server. http://www.tutorialspoint.com/spring/spring_mvc_hello_world_example.htm

I looked for similar problems here on this site and on other sites as well, but the suggested solutions didn‘t work for me. I would really appreciate some help, because I‘m pretty sure I‘m missing something basic here.

Here are my relevant files:

web.xml

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

<display-name>Spring MVC Application</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/HelloWeb-servlet.xml</param-value>
</context-param>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
<servlet>
    <servlet-name>HelloWeb</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>HelloWeb</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
</web-app>

HelloWeb-servlet.xml

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

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

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

</beans>

hello.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>

HelloController.java

package com.tutorialspoint;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;

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

   @RequestMapping(method = RequestMethod.GET)
   public String printHello(ModelMap model) {
      model.addAttribute("message", "Hello Spring MVC Framework!");

      return "hello";
   }

}

You have a single controller in your app, mapped to /hello (that‘s what @RequestMapping("/hello")means). The URL for that controller is thus http://localhost:8080/HelloWeb/hello.

 

以上是关于No mapping found for HTTP request with URI [/HelloWeb/] in DispatcherServlet with name 'HelloWeb的主要内容,如果未能解决你的问题,请参考以下文章

WARN PageNotFound: No mapping found for HTTP request with URI

关于No mapping found for HTTP request with URI...

java springmvc No mapping found for HTTP request with URI

springmvc搭建环境时报No mapping found for HTTP request with URI [/exam3/welcome] in DispatcherServlet with

No mapping found for HTTP request with URI [/HelloWeb/] in DispatcherServlet with name 'HelloWeb

为啥 Spring MVC 以 404 响应并报告“No mapping found for HTTP request with URI [...] in DispatcherServlet”?