2013-10-16 43 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'。 –

相关问题