1

当我从eclipse运行此项目时,出现404请求的资源()不可用,并且在地址栏中有http://localhost:8080/SpringMVCTest/web.xmlhttp://localhost:8080/SpringMVCTest/springMVCTest-servlet.xml。为什么它试图打开XML文件?Tomcat在Eclipse上运行Spring MVC项目时尝试打开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"; 
    } 
} 

回答

0

我会投上阴影这个:
你正在点击你的xml个文件,并选择运行

有它试图打开xml文件没有其他办法。我对吗?

修订
这些添加到您的web.xml

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

,然后再次运行。

+0

不,我只是点击运行图标然后选择运行在服务器上。 – AlyoshaKaramazov 2012-08-08 11:41:15

+0

配置是否正常? – 2012-08-08 11:56:55

+0

配置什么? – AlyoshaKaramazov 2012-08-08 12:18:54

相关问题