【发布时间】:2018-07-08 09:37:43
【问题描述】:
我在启动时遇到错误找不到带有 URI 的 HTTP 请求的映射
我知道已经有人问过这个问题,但是对于我的错误,即使我没有得到错误的解决方案,我也提到了这些问题。
错误日志
Jul 08, 2018 4:30:51 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'project'
Jul 08, 2018 4:30:51 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'project': initialization started
Jul 08, 2018 4:30:51 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'project-servlet': startup date [Sun Jul 08 16:30:51 IST 2018]; root of context hierarchy
Jul 08, 2018 4:30:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/project-servlet.xml]
Jul 08, 2018 4:30:52 PM org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler
INFO: Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0'
Jul 08, 2018 4:30:52 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'project': initialization completed in 806 ms
当我单击 index.jsp 中的提交按钮时,我只是试图从 Controller.java 中显示 Hello World
Error :
Jul 08, 2018 2:28:36 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/project/myMethod] in DispatcherServlet with name 'project'
Web Pages/index.jsp:
<html>
<body>
<form action="myMethod">
Username : <input name="un"><br/>
Password : <input name="pwd"><br/>
<input type="submit" value="Login">
</form>
</body>
</html>
Under
src/main/resources
com.project
Controll.java
package com.project;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Controll {
@RequestMapping("/myMethod")
public void CtrlMethod() {
System.out.println("Hello World");
}
}
web.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>project</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>project</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
project-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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd ">
<context:annotation-config />
<context:component-scan base-package="com.project"/>
</beans>
【问题讨论】:
-
我需要做哪些改变?
-
显然你在
project-servlet.xml中缺少<mvc:annotation-driven /> -
NO 仍然显示相同的错误:警告:在 DispatcherServlet 中找不到带有 URI [/project/myMethod] 的 HTTP 请求的映射,名称为 'project'
-
现在没有错误但我找不到Hello World消息请帮助
标签: java spring spring-mvc jsp servlets