Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当SpringMVC项目在Eclipse上运行时,Tomcat试图打开xml文件_Xml_Spring_Model View Controller_Tomcat_Http Status Code 404 - Fatal编程技术网

当SpringMVC项目在Eclipse上运行时,Tomcat试图打开xml文件

当SpringMVC项目在Eclipse上运行时,Tomcat试图打开xml文件,xml,spring,model-view-controller,tomcat,http-status-code-404,Xml,Spring,Model View Controller,Tomcat,Http Status Code 404,当我从eclipse运行这个程序时,我得到一个404,请求的资源不可用,并且在地址栏中有一个404http://localhost:8080/SpringMVCTest/web.xml 或http://localhost:8080/SpringMVCTest/springMVCTest-servlet.xml。为什么它试图打开xml文件 这是web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="ht

当我从eclipse运行这个程序时,我得到一个404,请求的资源不可用,并且在地址栏中有一个404http://localhost:8080/SpringMVCTest/web.xml 或http://localhost:8080/SpringMVCTest/springMVCTest-servlet.xml。为什么它试图打开xml文件

这是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>SpringMVCTest</display-name>

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

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

</web-app>
这是springMVCTest-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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
    <mvc:annotation-driven/>
    <mvc:resources mapping="/resources/**" location="/resources" />
    <context:component-scan base-package="/"></context:component-scan>

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

</beans>
这是控制器

import java.util.Map;

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



@Controller
public class SpringMVCTest {

    @RequestMapping({"/","/home"})
    public String showHomePage(Map<String, Object> model) {
        model.put("name", "Jess");
        return "home";
    }
}
我会在这上面投下阴影: 右键单击xml文件并选择RUN

它没有其他方法尝试打开xml文件。我说得对吗? 更新 将这些添加到web.xml中


然后再次运行。

不,我只是单击运行图标,然后选择在服务器上运行。是的,我想是这样。我包含了上面的文件。右键单击项目名称,然后选择“属性”。查看web项目设置是否正常。它的上下文根为SpringMVCTest。更新了答案,也检查了这个,并告诉我结果
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file> <!-- Your index page -->
</welcome-file-list>