问题描述:

  今天自己在搭建spring、springMVC、hibernate框架,搭建完成后,在引入jquery时,发现jquery不管用。我的解决顺序是:

1、检查路径,发现路径没错,另外需要注意的是,非rest风格的代码下,js资源一般为静态资源,不要放在web-inf下,否则会加载不上,另外注意js编码是否和当前页面编码一致,此处我设置utf-8编码。

<script src="${pageContext.request.contextPath }/js/jquery-1.4.2.js"  charset="utf-8"></script>

2、排错,我将jquery中代码直接复制到我的script里,发现是管用的,这至少说明,jquery没有问题。

3、控制台输出发现了问题所在:

14:57:55,021 DEBUG DispatcherServlet:823 - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/SSH_TEST/js/jquery-1.4.2.js]
14:57:55,022 DEBUG RequestMappingHandlerMapping:209 - Looking up handler method for path /js/jquery-1.4.2.js
14:57:55,023 DEBUG RequestMappingHandlerMapping:219 - Did not find handler method for [/js/jquery-1.4.2.js]

  第一句:DispatcherServlet 以get方式请求[/SSH_TEST/js/jquery-1.4.2.js]

  第三句:没有找到

4.解决方法:

  我的web.xml文件部分如下

<!-- springMVC核心控制器 -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springMVC.xml</param-value>
</init-param>
</servlet>
<!-- map all request to the dispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

  注意,黄色部分属于rest风格,即dispatcherServlet将处理所有web容器的请求,当请求加载静态资源jquery.js时,控制器类中没有写,因此会提示【Failed to load resource: the server responded with a status of 404 (Not Found)】,如果是传统的风格,非rest,一般静态资源时web容器自己就加载了。

  处理方法:在springMVC.xml文件添加如下。

<mvc:default-servlet-handler/>

  

jsp中引入jquery报错:Failed to load resource: the server responded with a status of 404 (Not Found)的更多相关文章

  1. 上传图片报错-Failed to load resource:the server responded with a status of 413(Request Entity Too Large)

    使用.netcore2.1 做文件上传时,要求是小于20M,上传3至5M都没问题,大于10M,提示错误[如标题],原来是nginx配置的原因 [HttpPost("Postcard" ...

  2. 报错解决——Failed to load resource: the server responded with a status of 404 (Not Found) favicon.ico文件找不到

    Django项目开发完成后在本地运行没问题,但在推到服务器上后出现报错Failed to load resource: the server responded with a status of 40 ...

  3. Failed to load resource: the server responded with a status of 404 (Not Found)

    Failed to load resource: the server responded with a status of 404 (Not Found) 报错情况:图标加载失败 原因分析:路径错误 ...

  4. ripple Failed to load resource: the server responded with a status of 404 (Not Found)

    在VS2015中使用Cordova + typescript开发中,遇到个问题. 在javascript console 中提示: Failed to load resource: the serve ...

  5. 待解决:2bootstrap-cerulean.css Failed to load resource: the server responded with a status of 404 ()

    2bootstrap-cerulean.css Failed to load resource: the server responded with a status of 404 ()

  6. Spring Boot Failed to load resource: the server responded with a status of 404 ()

    出现错误: Failed to load resource: the server responded with a status of 404 () 但是其他页面正常显示: 原因: 浏览器看一下:  ...

  7. Failed to load resource: the server responded with a status of 404 ()

    今天遇到了一个一开始感觉很莫名其妙的报错 在编写页面的时候把原先写在html页面里的js代码单独拿出来做成一个JavaScriptUtil文件,放在了和html页面同一个目录下.运行之后在对应的页面c ...

  8. Failed to load resource: the server responded with a status of 404 (Not Found) favicon.ico文件找不到

      今天使用sublime以localhost方式打开html文件时(使用wamp环境提供一个Apache服务器,html文件存在于wamp环境的www文件夹下),出现favicon.ico文件找不到 ...

  9. glyphicons-halflings-regular.woff2:1 Failed to load resource: the server responded with a status of 404 (Not Found)解决Web部署 svg/woff/woff2字体 404错误

    问题:最近在IIS上部署web项目的时候,发现浏览器总是报找不到woff.woff2字体的错误.导致浏览器加载字体报404错误,白白消耗了100-200毫秒的加载时间. 原因:因为服务器IIS不认SV ...

随机推荐

  1. SpringBoot document notes

    图片拷贝不过来,直接从github上下载 . 链接: https://github.com/DFX339/SpringBootDocumentNotes.git Create a example po ...

  2. delete和delete[] 区别

    // DeleteAndDelete[].cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h> ...

  3. 软件工程结对作业01 psp表格

  4. Python 基础关于编码

    一.编码的种类: 1 acsic码   基本不用    不同编码之间互用会产生乱码, 2unicode    A 字母  4个字节   00000000 00000000 00100100 01000 ...

  5. [ log4j ]-日志文件的使用

    在java文件中通过 log4j 输出日志信息 1,先引入 log4j-xx.x.jar 包 2,新建一个日志类 PrintLog4j.java: package com.stu.log4j; imp ...

  6. ajax参考增删改查

    AJAX做增删改查详细!   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...

  7. sqlite的数据类型

    参考sqlite官方文档:https://www.sqlite.org/datatype3.html 绝大多数的SQL数据库采用静态的.严格的数据类型,数据库中的值由数据表的列类型定义决定. 然而,s ...

  8. 键盘keycode对照表

  9. Python 函数的嵌套

    # 函数的互相调用 def func1(): print("我是神器的func1") def func2(): func1() print("我是神器的func2&quo ...

  10. 【Python】数据库练习-2

    1.    数据库一般作为存储作用,一般不用函数操作 2.    一次插入多条数据