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

相關問題