当前位置: 首页 > 知识库问答 >
问题:

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

夏侯航
2023-03-14


我使用Springmvc和IDE(Rad8.5.5)以及JettyIntegration版本8来创建一个小型web应用程序
当我尝试提交请求时http://localhost:9090/testJetty/index,Jetty返回以下错误消息:WARN org.springframework.web.servlet。PageNotFound-在名为“appServlet”的DispatcherServlet中找不到URI为[/testJetty/WEB-INF/views/index.jsp]的HTTP请求的映射。

这是我的代码:

<?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>
<?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。用Jdk 1.6 2编译的项目。Spring版4 3。Javax-servlet-api-3.1.0

我不知道是什么问题。有什么想法吗?谢谢

共有1个答案

况野
2023-03-14

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

但我想原因是因为您的jsp文件位于WEB-INF下,您需要在springconfiguration文件中添加以下代码:

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

另外,在< code>web.xml中将调度程序从< code>/*更改为< code>/

   <servlet-mapping>
        <servlet-name>app</servlet-name>
        <url-pattern>/</url-pattern>
   </servlet-mapping>
 类似资料: