spring app无法找到我的jsp索引页面的映射

时间:2011-02-07 11:44:16

标签: spring-mvc

我在使用spring 3和tomcat 7.0加载一个简单的index.jsp页面时遇到问题

我从tomcat日志中收到的错误是:

2011-02-07 11:36:18,510 DEBUG [org.springframework.web.servlet.DispatcherServlet] -  

DispatcherServlet with name 'raceLeague' processing GET request for [/Online Racing League/index.htm]>

2011-02-07 11:36:18,515 WARN [org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI [/Online Racing League/index.htm] in DispatcherServlet with name 'raceLeague'>

2011-02-07 11:36:18,515 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request>

这是我的web.xml的样子:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

<!-- Reads request input using UTF-8 encoding -->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Register and setup my servlet xml files here -->

<!-- Handles all requests into the application -->
    <servlet>
        <servlet-name>raceLeague</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/appServlet/servlet-context.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>raceLeague</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>    

这是我的servlet-context.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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        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">

    <!-- Scans the classpath of this application for @Components to deploy as beans -->
    <context:component-scan base-package="org.springframework.samples.mvc.basic" />

    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />

    <!-- Forwards requests to the "/" resource to the "welcome" view -->
    <mvc:view-controller path="/" view-name="welcome"/>

    <!-- Configures Handler Interceptors -->    
    <mvc:interceptors>
        <!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    </mvc:interceptors>

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources/ directory -->
    <mvc:resources mapping="/resources/**" location="/resources/" />

    <!-- Saves a locale change using a cookie -->
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />

    <!-- Application Message Bundle -->
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="/WEB-INF/messages/messages" />
        <property name="cacheSeconds" value="0" />
    </bean>

    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

最后我的index.jsp文件

<%@ include file="/WEB-INF/views/include.jsp" %>

<html>
  <head><title>Online racing league</title></head>
  <body>
    <h1>Test</h1>
   <table>

   <tr>
     <td><a href="uploadFile.htm">Upload a file</a></td>
     <td><a href="getAppList.htm?fileType=jar">Display App list</a></td>


   </tr>

   </table>
  </body>
</html>

我基本上遵循这个例子,所以我的projetc结构类似于http://blog.springsource.com/2009/12/21/mvc-simplifications-in-spring-3-0/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Interface21TeamBlog+%28SpringSource+Team+Blog%29

我也在使用eclipse IDE

1 个答案:

答案 0 :(得分:2)

当您的servlet绑定到<mvc:default-servlet-handler/>时,还需要/来提供静态资源。