在DispatcherServlet中找不到带有URI [/ HelloWeb /]的HTTP请求的映射,名称为“HelloWeb” [英] No mapping found for HTTP request with URI [/HelloWeb/] in DispatcherServlet with name 'HelloWeb'

查看:463
本文介绍了在DispatcherServlet中找不到带有URI [/ HelloWeb /]的HTTP请求的映射,名称为“HelloWeb”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在tomcat上部署我的项目,然后我收到此错误在DispatcherServlet中找不到带有URI [/ HelloWeb /]的HTTP请求的映射,名称为'HelloWeb'。

I am deploying my project on tomcat,then I am getting this error "No mapping found for HTTP request with URI [/HelloWeb/] in DispatcherServlet with name 'HelloWeb'".

这是我的网络xml文件
web.xml

this is my web xml file web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 version="3.0"
 metadata-complete="true">

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

 <servlet>
  <servlet-name>HelloWeb</servlet-name>
  <servlet-class>
     org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
   <servlet-name>HelloWeb</servlet-name>
   <url-pattern>/*</url-pattern>
</servlet-mapping>

</web-app>

我的 HelloWeb-servlet.xml

<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-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

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

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

</beans>

我的控制器 HelloController.java

package com.tutorialspoint.controller;

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
public class HelloController {

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

       return "hello";
    }
 }

hello.jsp

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

有人可以告诉我代码中有什么问题吗?

Can anyone please suggest me what is wrong in code?

推荐答案

我相信您正在遵循 tutorialspoint - Spring MVC的HelloWorld。我遇到了同样的问题,因为DispatcherServlet试图解决。

I believe that you are following the tutorial of tutorialspoint - HelloWorld for Spring MVC. I have the same issue which happens because DispatcherServlet try to resolve.

http://localhost:8080/HelloWeb/

它应该是:

http://localhost:8080/HelloWeb/hello

(把它放在你的网站上-browser)

(Put this in your web-browser)

或者它可以用另一种方式完成(如教程中所建议的)

Or it can be done another way (as suggested in that tutorial)


您应该注意,在给定的URL中,HelloWeb是应用程序
名称,hello是我们在
控制器中使用@RequestMapping(/ hello)提到的虚拟子文件夹。使用@RequestMapping(/)映射URL时可以使用直接root
,在这种情况下,
可以使用短URL访问同一页面
http: // localhost:8080 / HelloWeb / 但建议在不同文件夹下使用不同的
功能。

You should note that in the given URL, HelloWeb is the application name and hello is the virtual subfolder which we have mentioned in our controller using @RequestMapping("/hello"). You can use direct root while mapping your URL using @RequestMapping("/"), in this case you can access the same page using short URL http://localhost:8080/HelloWeb/ but it is advised to have different functionalities under different folders.

HelloWorldController 类中,你改变了这个:

in HelloWorldController class, you change this:

@RequestMapping("/hello")

到此:

@RequestMapping("/")

结果是你可以打电话 http:// localhost:8080 / HelloWeb / 没有任何问题。

the result is that you can call http://localhost:8080/HelloWeb/ without any problem.

希望有所帮助!

这篇关于在DispatcherServlet中找不到带有URI [/ HelloWeb /]的HTTP请求的映射,名称为“HelloWeb”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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