简体   繁体   English

为什么我的Spring MVC项目出现404错误?

[英]Why am I getting a 404 error with my Spring MVC project?

I have very basic setup for a spring mvc web application. 我有一个针对Spring MVC Web应用程序的非常基本的设置。 Here is my web.xml mapping below: 这是下面的我的web.xml映射:

<servlet>
    <servlet-name>test</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:spring-config.xml</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>test</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

and spring-config.xml 和spring-config.xml

<mvc:default-servlet-handler/>

<mvc:annotation-driven />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/pages/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>
<context:component-scan base-package="cz.dmostek"/>

<context:annotation-config/>

and this is my directory structure for the jsp pages 这是我的jsp页面的目录结构

`-- web
    `-- WEB-INF
        |-- pages
        |   |-- css
        |   |   |-- foundation.css
        |   |   `-- normalize.css
        |   |-- images
        |   |-- index.jsp
        |   `-- js
        `-- web.xml

and my controller is declared below: 我的控制器声明如下:

@Controller
public class TestController {


    @RequestMapping(value = "/")
    public String 
        return "index";
    }
}

However, when i try to access localhost:8080/app/ I got 404 error. 但是,当我尝试访问localhost:8080 / app /时,出现404错误。 In the log I have 2013-10-19 16:12:09,326 () DEBUG DispatcherServlet - Successfully completed request 在日志中,我有2013-10-19 16:12:09,326 () DEBUG DispatcherServlet - Successfully completed request

and if i debug the app everything seems ok, controller is called, view is rendered, but i am still getting 404. What do you think? 如果我调试该应用程序,一切似乎都正常,将调用控制器,呈现视图,但我仍会收到404。您怎么看?

Forget a xml-based configurations for Spring projects. 忘记Spring项目的基于xml的配置。 This approach is really obsolete. 这种方法确实过时了。 Here you can find a well explained step by step tutorial for simple Spring annotation based application. 在这里,您可以找到有关简单的基于Spring批注的应用程序的逐步讲解的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring MVC,为什么会出现 404 错误? - Spring MVC, Why am I getting a 404 error? 为什么在访问我的 Spring MVC 应用程序 URL 时出现 404 错误? - Why am I getting a 404 error when accessing my Spring MVC app URL? 为什么我的 Spring Boot Web 应用程序会出现 404 错误? - Why am I getting a 404 error in my Spring Boot Web app? 为什么我在 spring mvc 中收到 @Valid 错误 - Why am i getting an error on @Valid in spring mvc 我的主页不适用于Spring MVC Web应用程序。运行应用程序时出现404错误。请 - My home page not working for spring mvc web app.When I am running the application I am getting 404 error.Please 在Eclipse中使用Spring MVC 5的新项目,但出现错误404 - New project using Spring MVC 5 in eclipse, but I am having error 404 为什么我在运行一个简单的 spring 启动 gradle 项目时得到 404 状态? - Why am I getting 404 status on running a simple spring boot gradle project? Spring MVC java Configuration类没有调用,所以我收到404错误 - Spring MVC java Configuration class is not calling , so i am getting 404 error spring和angulaJS(我收到类似HTTP Status 404的错误) - spring and angulaJS(i am getting error like HTTP Status 404 ) 我在Spring Boot中遇到API调用404错误 - I am getting a 404 Error on API Call in Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM