【问题标题】:noHandlerFound and showing 404 with no message in spring mvcnoHandlerFound 并在 spring mvc 中显示 404 且没有消息
【发布时间】:2017-11-24 19:46:27
【问题描述】:

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>withDiffServletName</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>example</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>example</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

example-servlet.xml

<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-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
   <context:component-scan base-package = "com.app.simple" />
   <mvc:annotation-driven />
   <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name = "prefix" value = "/" />
      <property name = "suffix" value = ".jsp" />
   </bean>
</beans>

控制器

@Component
public class ConrrollController 
{
    @RequestMapping(value = "/student", method = RequestMethod.GET)
       public ModelAndView student() {
          return new ModelAndView("student", "command", "hi");
       }
}

index.jsp /学生

学生.jsp 嗨

大家好, 我是春天的新手,这是我的第一个程序出错了 org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:在名称为“sample”的 DispatcherServlet 中未找到带有 URI [/webroot/student] 的 HTTP 请求的映射。 请为我提供解决方案并鼓励我。

我不明白 Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?

【问题讨论】:

    标签: spring jsp spring-mvc spring-security servlet-3.0


    【解决方案1】:

    没有处理程序映射出现,因为控制器没有返回视图。 所以我们需要改变@controller 而不是@components

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 2016-02-13
      • 1970-01-01
      • 2017-12-16
      • 2021-06-29
      • 2013-10-09
      相关资源
      最近更新 更多