问题描述:

  今天自己在搭建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. 2.BIND服务基础及域主服务器配置

    一.BIND 现今使用最晚广泛的DNS服务器软件是BIND(Berkeley Internet Name Domain),最早由伯克利大学的一名学生编写,现在最新的版本是9,由ISC(Internet ...

  2. 平面图转对偶图&19_03_21校内训练 [Everfeel]

    对于每个平面图,都有唯一一个对偶图与之对应.若G‘是平面图G的对偶图,则满足: G'中每一条边的两个节点对应着G中有公共边的面,包括最外部无限大的面. 直观地讲,红色标出来的图就是蓝色标出的图的对偶图 ...

  3. day06 小数据池,再谈编码

    今日所学 一.  小数据池 二.  is 和==的区别 三.  编码的问题 一.小数据池的作用 用来缓存数据 可以作用的数据类型: 整数(int), 字符串(str), 布尔值(bool). 什么是块 ...

  4. C++模板类之pair

    Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型,第一个元素是int型的 ...

  5. relativeURL 相对URL的坑

    我正在尝试实现一个使用RestKit的iOS应用程序.在我迄今为止看到的所有示例中,以下代码用于创建URL: NSURL *baseURL = [NSURL URLWithString:@" ...

  6. 第三篇 功能实现(2) (Android学习笔记)

    第三篇 功能实现(2) ●Activity的四种启动模式 Activity的启动模式有四种,分别是standard.singleTop.singleTask和singleInstance. 在Andr ...

  7. Java的第一个晞月自己打的程序

    1.编写一个程序,求1!+2!+…+10!的值. package xxx; public class abc { public static void main(String args[]) { in ...

  8. MyEclipse使用教程:在Web项目中使用Web片段

    MyEclipse 在线订购年终抄底促销!火爆开抢>> MyEclipse最新版下载 本教程向用户展示了使用关联的Web项目创建Web片段项目的机制.用户还可以获得要检查的示例项目.在本教 ...

  9. debug fortran

    exmple: gfortran -g -fcheck=all -Wall segf.f90

  10. powerdesigner 实体关系模型CDM与物理数据模型PDM互转

    1.创建CDM 2.CDM转换PDM 3.PDM转CDM 环境 powerdesigner15.1 1.创建CDM File --> new Model-->Conceptual data ...