【问题标题】:Tomcat trying to open xml files when Spring MVC project run on Eclipse当 Spring MVC 项目在 Eclipse 上运行时,Tomcat 尝试打开 xml 文件
【发布时间】:2012-08-05 12:04:38
【问题描述】:

当我从 Eclipse 运行它时,我得到一个 404 请求的资源()不可用,并且在地址栏中我有 http://localhost:8080/SpringMVCTest/web.xmlhttp://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 spring model-view-controller tomcat http-status-code-404


    【解决方案1】:

    我会对此投下阴影:
    您正在右键单击您的 xml 文件并选择“运行”

    没有其他方法可以尝试打开xml 文件。我说的对吗?

    已更新
    将这些添加到您的web.xml

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file> <!-- Your index page -->
    </welcome-file-list>
    

    然后再次运行。

    【讨论】:

    • 不,我只是点击运行图标,然后选择在服务器上运行。
    • 是的,我想是的。我包含了上面的文件。
    • 右键单击您的项目名称,然后选择properties。看看web project settings 是否正常。
    • 它的上下文根为 SpringMVCTest。
    • 更新了答案,也检查一下,让我知道结果
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 2016-08-08
    • 2014-09-25
    • 1970-01-01
    • 2011-02-05
    • 2014-12-02
    • 2012-10-05
    相关资源
    最近更新 更多