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

在名为“SpringMVC”的DispatcherServlet中,未找到URI为[/SpringMVC/]的HTTP请求映射

柳弘方
2023-03-14

我在我的SpringMVC项目中得到了这个错误。我必须在浏览器中手动添加完整的路径来运行代码,但我不能直接运行它。

     org.springframework.web.servlet.DispatcherServlet noHandlerFound
            WARNING: No mapping found for HTTP request with URI [/SpringMVC/] in DispatcherServlet  with name 'SpringMVC'

web.xml:

            <?xml version="1.0" encoding="UTF-8"?>
            <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
            <display-name>SpringMVC</display-name>
            <welcome-file-list>
            <welcome-file>index.html</welcome-file>
            <welcome-file>index.htm</welcome-file>
            <welcome-file>index.jsp</welcome-file>
            <welcome-file>default.html</welcome-file>
            <welcome-file>default.htm</welcome-file>
            <welcome-file>default.jsp</welcome-file>
            </welcome-file-list>
            <servlet>
            <servlet-name>SpringMVC</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
            </servlet>
            <servlet-mapping>
            <servlet-name>SpringMVC</servlet-name>
            <url-pattern>/</url-pattern>
            </servlet-mapping>
            </web-app>
            <?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-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.adept.springMVC"></context:component-scan>
            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="suffix" value=".jsp"></property>

            </bean>

            </beans>
            package com.adept.springMVC;

            import org.springframework.stereotype.Controller;
            import org.springframework.ui.ModelMap;
            import org.springframework.web.bind.annotation.ModelAttribute;
            import org.springframework.web.bind.annotation.RequestMapping;
            import org.springframework.web.bind.annotation.RequestMethod;
            import org.springframework.web.servlet.ModelAndView;
            @Controller
            public class StudentControler {
            @RequestMapping(value="/student1",method=RequestMethod.GET)
            public ModelAndView student1(){
            return new ModelAndView("student", "command", new Student());
            }
            @RequestMapping(value="/addStudent",method=RequestMethod.POST)
            public String addStudent(@ModelAttribute("springWeb1")Student stud,ModelMap map){
            map.addAttribute("name",stud.getName());
            map.addAttribute("id", stud.getId());
            map.addAttribute("dept", stud.getDept());
            return "result";
            }
           }
            <%@ page language="java" contentType="text/html; charset=UTF-8"
            pageEncoding="UTF-8"%>
            <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
            <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org /TR/html4/loose.dtd">
            <html>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Spring MVC</title>
            </head>
            <body>
            <h1>Student Information</h1>
            <form:form method="post" action="/SpringMVC/addStudent">
            <table>
            <tr>
            <td><form:label path="name">Name:</form:label></td>
            <td><form:input path="name" /></td>
            </tr>
            <tr>
            <td><form:label path="id">Id:</form:label></td>
            <td><form:input path="id" /></td>
            </tr>
            <tr>
            <td><form:label path="dept">Department:</form:label></td>
            <td><form:input path="dept" /></td>
            </tr>
            <tr>
            <td colspan="2">
            <input type="submit" value="Submit"/>
            </td>
            </tr>
            </table>  
            </form:form>

            </body>
            </html>
            <%@ page language="java" contentType="text/html; charset=UTF-8"
            pageEncoding="UTF-8"%>
            <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
            <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
            <html>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Output</title>
            </head>
            <body>
            <h1>Student Information</h1>
            <table>
            <tr>
            <td>Name:</td>
            <td>${name}</td>
            </tr>
            <tr>
            <td>Id:</td>
            <td>${id}</td>
            </tr>
            <tr>
            <td>Department:</td>
            <td>${dept}</td>
            </tr>
            </table>  
            </body>
            </html>

共有1个答案

林冥夜
2023-03-14

将springmvc-servlet.xml更改为大写的springmvc-servlet.xml

 类似资料: