首页 文章

noHandlerFound并在spring mvc中显示404没有消息

提问于
浏览
0

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>

例如-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 / student

student.jsp你好

大家好,我是 Spring 天的新手,这是我的第一个程序,得到一个错误org.springframework.web.servlet.DispatcherServlet noHandlerFound警告:在名称为'的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"?

1 回答

  • 0

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

相关问题