0
I tried to to load a simple example of spring mvc with a simple jsp but failed with the following error: No mapping found for HTTP request with URI [/SpringHello/WEB-INF/jsp/hello.jsp] I'm using Spring 3.2.2. I really appreciate your help here. I tried several thing but still it seems that I can not map my jsp page in the controller.

我尽我所能查看了这里的其他答案,但似乎没有什么完全适合我的问题/解决我的问题。本质上。

我觉得我已经正确完成了映射,但显然我没有。所以在这里我会发布任何看起来可能相关的文件。

我的控制器类是:

    package net.viralpatel.spring3.controller;

    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;

    @Controller
    @RequestMapping("/hello")
    public class HelloController{

       @RequestMapping(method = RequestMethod.GET)
       public String printHello(ModelMap model) {
           System.out.println("Hello Spring MVC Framework!**********************");
          model.addAttribute("message", "Hello Spring MVC Framework!");
          return "hello";
       }

    }

我的 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"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="WebApp_ID" version="2.5">
        <display-name>Spring3MVC</display-name>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
        <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-servlet.xml</param-value>
      </context-param>

      <listener>
           <listener-class>
              org.springframework.web.context.ContextLoaderListener
           </listener-class>
      </listener>
        <servlet>
            <servlet-name>spring</servlet-name>
            <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>spring</servlet-name>
            <url-pattern>/*</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"
        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="net.viralpatel.spring3.controller" />    
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="prefix">
                <value>/WEB-INF/jsp/</value>
            </property>
            <property name="suffix">
                <value>.jsp</value>
            </property>
            </bean>

    </beans>

我的 hello.jsp 是:

    <html>
    <head>
        <title>Spring 3.0 MVC Series: Hello World - ViralPatel.net</title>
    </head>
    <body>
        ${message}
    </body>
    </html>

    I am trying to run my hello.jsp with "http:ipAddress:8080/SpringHello/hello" but I am getting "HTTP Status 404 - /SpringHello/hello" .

里面的日志它给出了警告:

    Oct 16, 2013 10:08:30 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Oct 16, 2013 10:08:30 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 457 ms
Oct 16, 2013 10:08:30 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Oct 16, 2013 10:08:30 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.4
Oct 16, 2013 10:08:30 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Oct 16, 2013 10:08:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Oct 16, 2013 10:08:30 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Oct 16, 2013 10:08:30 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Wed Oct 16 22:08:30 IST 2013]; root of context hierarchy
Oct 16, 2013 10:08:30 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
Oct 16, 2013 10:08:31 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@973f09: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
Oct 16, 2013 10:08:31 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 668 ms
Oct 16, 2013 10:08:31 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
Oct 16, 2013 10:08:31 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'spring': initialization started
Oct 16, 2013 10:08:31 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Wed Oct 16 22:08:31 IST 2013]; parent: Root WebApplicationContext
Oct 16, 2013 10:08:31 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
Oct 16, 2013 10:08:31 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@119510f: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@973f09
Oct 16, 2013 10:08:31 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello] onto handler 'helloController'
Oct 16, 2013 10:08:31 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello.*] onto handler 'helloController'
Oct 16, 2013 10:08:31 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello/] onto handler 'helloController'
Oct 16, 2013 10:08:31 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'spring': initialization completed in 349 ms
Oct 16, 2013 10:08:32 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
Oct 16, 2013 10:08:32 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'spring': initialization started
Oct 16, 2013 10:08:32 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Wed Oct 16 22:08:32 IST 2013]; root of context hierarchy
Oct 16, 2013 10:08:32 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
Oct 16, 2013 10:08:32 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@f2ad66: defining beans [helloWorldController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,viewResolver,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
Oct 16, 2013 10:08:32 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello] onto handler 'helloWorldController'
Oct 16, 2013 10:08:32 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello.*] onto handler 'helloWorldController'
Oct 16, 2013 10:08:32 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello/] onto handler 'helloWorldController'
Oct 16, 2013 10:08:32 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'spring': initialization completed in 689 ms
Oct 16, 2013 10:08:32 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Oct 16, 2013 10:08:32 PM org.apache.jk.common.ChannelSocket init
INFO: JK2: ajp13 listening on /0.0.0.0:8009
Oct 16, 2013 10:08:32 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/17  config=null
Oct 16, 2013 10:08:32 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2613 ms
Hello Spring MVC Framework!**********************
Oct 16, 2013 10:08:42 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringHello/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'spring'

请帮助我,我是春天的新手,我花了 3 天多的时间来解决这个问题。

4

1 回答 1

0

您没有路径的处理程序/SpringHello/WEB-INF/jsp/hello.jsp。您应该将您的请求发送到

/SpringHello/hello

HelloController这是由您的班级映射的。

于 2013-10-16T17:49:36.437 回答