gpt4 book ai didi

java - Spring MVC - noHandlerFound/PageNotFound

转载 作者:行者123 更新时间:2023-12-02 03:09:45 25 4
gpt4 key购买 nike

我发现很多类似的问题都询问了我遇到的问题,并尝试了很多解决方案,但似乎都不起作用。

最奇怪的是,我的一位同事可以运行该程序,因此代码不是问题。

我收到的错误是当我运行应用程序时,我无法访问 welcomepage.htmlhellopage.html

déc. 20, 2016 9:42:37 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound AVERTISSEMENT: No mapping found for HTTP request with URI [/SpringMVC/hellopage.html] in DispatcherServlet with name 'spring'

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

</web-app>

spring-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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="springframework.org/schema/mvc"
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.javatpoint"></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>

HelloWorldController.java

package com.javatpoint;  
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloWorldController {

@RequestMapping("/hello")
public ModelAndView helloWorld() {

String message = "HELLO SPRING MVC";
return new ModelAndView("hellopage", "message", message);
}

}

WelcomeWorldController.java

package com.javatpoint;

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

@Controller
public class WelcomeWorldController {

@RequestMapping("/welcome")
public ModelAndView helloWorld() {

String message = "WELCOME SPRING MVC";
return new ModelAndView("welcomepage", "message", message);
}

}

index.jsp

<html>
<body>
<a href="hellopage.html">click</a>
|
<a href="welcomepage.html">click</a>
</body>
</html>

这是我使用 tomcat 7.0.73 运行的 Maven 项目

有项目目录的结构

/image/PmNBm.png

最佳答案

正如您所说,代码在您 friend 的系统上运行时没有问题,我假设配置存在问题。

请验证所有配置文件和 pom.xml 中的项目名称是否正确

关于java - Spring MVC - noHandlerFound/PageNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41239194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com