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

简介: I'm learning the Spring Framework, and I'm doing the HelloWeb tutorial on tutorialspoint, and I can't get it working.

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.

 

相关文章
|
7月前
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must b
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must b
81 0
|
4月前
|
监控 搜索推荐 定位技术
HTTP状态码:如何修复 404 Not Found错误?
互联网上各种类型的网站非常多,无论用户还是网站运营者不可避免的会遇到404 Not Found错误,如果遇到404错误,我们应该如何解决呢?
34 1
|
6月前
|
Java Maven Spring
org.springframework.boot:spring-boot-starter-parent’ not found
org.springframework.boot:spring-boot-starter-parent’ not found
61 0
|
7月前
Android-async-http 添加token get方法报错 No valid URI scheme was provided
Android-async-http 添加token get方法报错 No valid URI scheme was provided
|
8月前
|
自然语言处理
HTTP协议中 URI、URL、URN
HTTP协议中 URI、URL、URN
80 0
|
9月前
|
缓存 Linux 开发工具
centos 7 yum安装失败(HTTP Error 404 - Not Found)的解决方法
centos 7 yum安装失败(HTTP Error 404 - Not Found)的解决方法
609 0
|
11月前
|
缓存
Project ‘org.springframework.boot:spring-boot-starter-parent:1.5.7.RELEASE‘ not found
Project ‘org.springframework.boot:spring-boot-starter-parent:1.5.7.RELEASE‘ not found
|
12月前
|
缓存
project ‘org.springframework.boot:spring-boot-starter-parent:2.1.4.RELEASE‘ not found
project ‘org.springframework.boot:spring-boot-starter-parent:2.1.4.RELEASE‘ not found
127 0
|
12月前
|
Java Spring
Spring 定时任务报错:Cron expression must consist of 6 fields (found 5 in “0 * * * *“)
Spring定时任务-cron只能包含6个字段,即使不支持年份
1131 0
|
12月前
|
Java
问题排查之'org.apache.rocketmq.spring.starter.core.RocketMQTemplate' that could not be found.- Bean metho...
问题排查之'org.apache.rocketmq.spring.starter.core.RocketMQTemplate' that could not be found.- Bean metho...
240 0