Spring MVC 与 Eclipse Jetty 集成 8 - 未找到具有 URI 的 HTTP 请求的映射

Spring MVC with Eclipse Jetty integration 8 - No mapping found for HTTP request with URI


我正在使用 Spring mvc with IDE (Rad 8.5.5) 和 Jetty Integration version 8 创建一个小型 web 应用程序。
当我尝试提交请求 http://localhost:9090/testJetty/index 时,Jetty returns 出现以下错误消息:WARN org.springframework.web.servlet.PageNotFound - 找不到映射在名称为 'appServlet'.

的 DispatcherServlet 中使用 URI [/testJetty/WEB-INF/views/index.jsp] 的 HTTP 请求

这是我的代码:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
    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_3_0.xsd">
    <display-name>testJetty</display-name>

    <servlet>
        <servlet-name>app</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>app</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

应用-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
                        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

    <context:component-scan base-package="test"/>

    <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />

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

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
        <beans:property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
    </beans:bean>
</beans:beans>

控制器:

package test;

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

@Controller
public class test {

    @RequestMapping(value = "/index")
    public String index(Model model) {
        return "index";
    }
}


无法更改以下要求: 1.用Jdk1.6编译的项目 2. Spring 版本 4 3.Javax-servlet-api-3.1.0

我不明白是什么问题。有任何想法吗? 谢谢。

由于我们没有看到您的项目结构,所以它可能不正确。

但我猜是因为你的jsp文件在WEB-INF下,你需要在你的spring配置文件中加入如下代码:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
</bean>

同时在 web.xml

中将您的调度员从 /* 更改为 /
   <servlet-mapping>
        <servlet-name>app</servlet-name>
        <url-pattern>/</url-pattern>
   </servlet-mapping>