gpt4 book ai didi

java - org.springframework.web.servlet.DispatcherServlet noHandlerFound 404错误响应

转载 作者:行者123 更新时间:2023-12-02 04:42:18 25 4
gpt4 key购买 nike

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>sample</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sample</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

我在其中添加表单和操作“输出”的索引文件

<html>
<body> <form action="output">
<input type="text" name="t1"></br> <input type="text" name="t2"></br>
<input type="submit">
</form>
</body>
</html>

servlet 配置如下

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.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/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.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-3.0.xsd">

<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.guni.Controllers"></context:component-scan>
</beans>

sampleController.java

package com.guni;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class sampleController {
@RequestMapping(value="/output", method = RequestMethod.GET)
public String karna()
{
return "sampleOutput.jsp";
}
}

我正在尝试使用提交按钮执行表单 GET。提交按钮没有任何反应。该网页给我404错误。任何人都有任何想法。我正在使用 eclipse 2019 和 tomcat9。我正在尝试使用 spring 4.0 在 Maven 中创建一个 Web 应用程序

当我运行该项目时,出现以下错误 org.springframework.web.servlet.DispatcherServlet noHandlerFound 没有 GET/demoMVC/output 的映射

最佳答案

当您在 /demoMVC/output 上执行 GET 请求时,您的 Controller 方法已注册为接受 /output 上的 GET 请求。将您的 @RequestMapping 值修改为 /demoMVC/output,或者更改您在浏览器中调用的 URL。

此外,在许多情况下,InternalResourceViewResolver 配置为返回不带 .jsp 后缀的 JSP 文件名称。假设您创建了一个名为 sampleOutput.jsp 的文件,请调整您的 karna() 方法以返回 "sampleOutput" 而不是 "示例输出.jsp”。如果这不起作用,您可以发布您的 InternalResourceViewResolver 配置吗?

关于java - org.springframework.web.servlet.DispatcherServlet noHandlerFound 404错误响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56509835/

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