【问题标题】:org.springframework.web.servlet.DispatcherServlet noHandlerFound 404 error responseorg.springframework.web.servlet.DispatcherServlet noHandlerFound 404 错误响应
【发布时间】:2019-10-23 21:02:46
【问题描述】:
<?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 没有映射

【问题讨论】:

    标签: java spring maven web model-view-controller


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-02-18
      • 1970-01-01
      • 2014-01-31
      • 1970-01-01
      • 2013-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      相关资源
      最近更新 更多