zoukankan      html  css  js  c++  java
  • 哪些情况会报 404

     
     
    有哪些情况会出现404?
     
    以下为我从出现的情况中得到的一些结论:
    1、路径真的不存在,没有访问到服务器,浏览器解析为404
    2、访问到了服务器,但是要访问的那个具体的资源(接口)不存在,在服务器的逻辑下,跳转到404.jsp
    3、访问到了服务器,要访问的接口也存在,但是在程序执行到接口之前(拦截器之类的),就出了错,跳转到404.jsp
    4、访问到了服务器,也访问到了接口,但是在执行过程中程序出错了,也会出现404(忘了是浏览器的404,还是服务器的404.jsp)
    确定了不是第一种情况之后,可以在访问的接口打断点,看看程序是否会执行到接口的断点,如果执行到了,那么是4,否则,可能是2或者3
     
    下文的问题,就是遇到了第2种情况(注解写错、类没有被扫描到)
     
    问题:
    在 postman 中访问 http://localhost:8011/post-manager/test/t 时,status 的值为 404, “页面”显示内容为(跳转到了404.jsp): 
     
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>error</title>
            <link rel="stylesheet" href="http://localhost:8011/post-manager/static/css/reset.css"/>
            <link rel="stylesheet" href="http://localhost:8011/post-manager/static/css/basic.css"/>
            <link rel="stylesheet" href="http://localhost:8011/post-manager/static/css/style.css"/>
            <script type="text/javascript" src="http://localhost:8011/post-manager/static/js/jquery-1.10.2.min.js">
     
      </script>
        </head>
        <body>
            <!--内容-->
            <div class="content">
                <div class="content-box cont-word">
                    <img src="http://localhost:8011/post-manager/static/img/fail.png" alt="" class="succ-img"/>
                    <span class="succ-txt">访问资源不存在,请检查请求路径是否正确!!</span>
                    <p>
                        <br>
                        <input name="" type="submit"  value="返回"  class="submit-butn capa-butn"
                 onclick="window.history.go(-1)"/>
                    </div>
                    <div class="footer g">
                        <p>@2017 请联系****管理员</p>
                    </div>
                </div>
            </body>
        </html>
     
    首先,可以确定控制台没有报错
    由于 post-manager 工程中之前没有 controller 类,TestController 类是我的新加的第一个 controller 类,连 controller 的 package 都是新加的,所以有可能是没有被扫描到的问题?
    确实可能是扫描的问题:
    在 spring-mvc.xml 文件中,有如下配置:
     
    <!-- 自动扫描且只扫描@Controller -->
    <context:component-scan base-package="com.kexin.prc.join.post.web" use-default-filters="false">
       <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
       <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>
     
    即只配置了扫描包
     
    com.kexin.prc.join.post.web
    下的 controller 类,
    将 TestController 类转移到该包中,尝试一下
     
    问题解决,成功访问
     
     
     

    2019.3.4 补充
     
    又遇到了一次 404,最终发现原因是数据库连接信息配置错误
    但是在刚开始启动 tomcat 的时候,控制台不报任何错,而是在启动了一会儿之后再在控制台报错
    所以一开始并不知道 404 的原因是这个(即,一开始以为 tomcat 启动成功了,但实际上 tomcat 并没有启动成功)
     
     
  • 相关阅读:
    运算符,可变不可变数据类型
    基本的数据类型
    Python_day1
    day2_操作系统
    git fetch 命令
    Git branch 命令
    tmux常用命令
    转载-struts中logic标签使用
    转载-SVN常用命令
    javascript判断图片加载完成的三种方法
  • 原文地址:https://www.cnblogs.com/stone94/p/8596900.html
Copyright © 2011-2022 走看看