当前位置: 首页 > 知识库问答 >
问题:

org.springframework.web.servlet.找到了HTTP请求与URI的映射。我已经将项目部署为maven项目

韦锦程
2023-03-14

我已经在许多线程中寻找了解决方案,但没有任何东西对我有效。每当我输入这个网址http://localhost:8080/springMVC/web-app/WEB-INF/index。html显示以下错误。

Aug07, 2016 7:21:35PMorg.springframework.web.servlet.页面未找到noHandler找到

警告:在名称为MyDemo的DispatcherServlet中找不到与URI[/springMVC/web-app/WEB-INF/index.html]的HTTP请求的映射

这是我的网站。xml文件。

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
 <display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>MyDemo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-  class>

<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyDemo</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

</web-app>

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: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-4.0.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-4.2.xsd">
<mvc:annotation-driven></mvc:annotation-driven>

<mvc:default-servlet-handler/>

<context:component-scan base-package="com.demo.controller.*"></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>

</beans>

MyDemoController.java

package com.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller

public class MyDemoController {

@RequestMapping(value="/index") 
public String getqoute(Model model)
{
    model.addAttribute("random","To be");
    return "quote";
}



}

有什么建议吗?

共有1个答案

司马辉
2023-03-14

base package=“com.demo.controller.*”

将其更改为base package=“com.demo.controller”

也可以使用@Request estMap("/index")

 类似资料: