1

Eclipseからこれを実行すると、404が表示され、要求されたresource()が使用できず、アドレスバーにhttp://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";
    }
}
4

1 に答える 1

0

私はこれに影を落とします:
あなたはあなたのxmlファイルを右クリックして実行を選択しています

ファイルを開こうとする他の方法はありませんxml。私は正しいですか?

更新
これらをあなたのweb.xml

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

そして、もう一度実行します。

于 2012-08-08T11:34:13.483 に答える