无法访问Spring MVC中的本地网页

时间:2015-06-02 22:40:32

标签: java spring jsp spring-mvc

我开始从复数视角学习'Introduction to Spring MVC'课程。 当我尝试访问http://localhost:8080/FitnessTracker/greeting.html时,我得到HTTP Status 404。我有权访问显示localhost:8080/FitnessTracker的{​​{1}}。在教程中一切正常,所以我很困惑,因为我做了同样的事情。

的web.xml

index.jsp

servlet的config.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<servlet>
    <servlet-name>fitTrackerServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/servlet-config.xml</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>fitTrackerServlet</servlet-name>
    <url-pattern>*.html</url-pattern>

</servlet-mapping>

<display-name>Archetype Created Web Application</display-name>

HelloController.java

<?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:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvchttp:  //www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-3.2.xsd">

<mvc:annotation-driven/>
<context:component-scan base-package="com.sergey.controller"/>

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

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

的hello.jsp

package com.sergey.controller;

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

@Controller
public class HelloController {

@RequestMapping(value ="/greeting")
public String sayHello (Model model) {

    model.addAttribute("greeting", "Hello World");

    return "hello";
}
}

我的目录结构:

  • FitnessTracker
    • SRC
        • 的java
          • COM /布林/控制器
            • HelloController.java
        • 资源
        • web应用
          • WEB-INF
            • 配置
              • servlet的config.xml中
            • JS​​P
              • 的hello.jsp
            • 的web.xml
          • 的index.jsp
    • 的pom.xml

1 个答案:

答案 0 :(得分:0)

亲爱的СергейСиротинин,

我尝试过同样的事情。 我所做的就是删除

info

标签以及我的jars版本3.0替换为servlet-config.xml中的<mvc:annotation-driven/>

请尝试相同。