2013-10-16 42 views
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. 

我已經通過其他的答案看着這裏,盡我所能名「春秋」 ,但似乎完全不符合我的問題/解決我的問題。本質。春警告沒有找到映射與HTTP請求的URI [/SpringHello/WEB-INF/jsp/hello.jsp在DispatcherServlet的與

我覺得我有正確的映射,但顯然我沒有。所以在這裏我會發布任何看起來可能相關的文件。

我的控制器類是:

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> 

我的彈簧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.s[email protected]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.s[email protected]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.s[email protected]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.s[email protected]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天解決這個問題。

+0

上下文的名稱是什麼? –

回答

0

您沒有路徑/SpringHello/WEB-INF/jsp/hello.jsp的處理程序。您應該發送您的請求到

/SpringHello/hello 

它由您的HelloController類映射。

+0

不要編輯我的答案。發表評論。 –

+0

我使用動態web項目在eclipse中創建了我的項目。我的項目名稱是「SpringHello」,我試圖在tomcat中的eclipse中運行它。 –

+0

@NileshShukla在'jsp'上按'run'是沒有意義的。轉到您的瀏覽器並將您的URL地址設置爲我的答案中的內容,而不是'/ SpringHello/WEB-INF/jsp/hello.jsp'。 –

相關問題