问题描述:

  今天自己在搭建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. java 一些容易忽视的小点-控制语句

    随机数 .Math.random()该方法用于产生一个0到1区间的double类型的随机数,但是不包括1 if-else循环语句 如果if语句不写{},则只能作用于后面的第一条语句 switch语句 ...

  2. 4.2计算字符的ASCII碼

    Q:终端输入一个字符,输出ASCII碼 #include<stdio.h> int main() { char c; printf("input a charscter:&quo ...

  3. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  4. 银联接口C#

    银联支付: ChinaPay的会员商户接入支付平台,以方便商户开展网上支付交易. 持卡人从商户网站中生成订单信息,通过公共支付交易平台中的支付网关子系统进行支付的过程,其交易流程包括订单确认.支付处理 ...

  5. python2和python3的区别总结

    python2x和python3x区别: python2x:源码重复,不规范. python3x:  源码规范,优美,清晰,简单. 编译型:将代码一次性全部转化成字节码. 代表语言:C,C++ 优点: ...

  6. jsp自定义标签开发

    参考:http://blog.csdn.net/lw001x/article/details/7589302

  7. mysql 内置函数和sql server 内置函数的区别

    以下函数均没有对参数做说明,使用的使用需要了解其参数内容 数据库 sql server mysql oracle 举例 获得当前系统时间 getdate() now() sysdate  注意不是函数 ...

  8. jQuery操错题积累

    1: 解析: onBlur:焦点移除事件. onfocus:定义和用法 onfocus 事件在对象获得焦点时发生 onchange:定义和用法 onchange 事件会在域的内容改变时发生 nclic ...

  9. Python的网络编程--思维导图

    Python的网络编程--思维导图

  10. mysql存储过程造数

    性能测试时,数据库表通常需要很多数据,此时我们可以用存储过程来造数,以下代码mysql.Oracle都可以用 首先,先查看数据库表的设计,可以看到每张表有多少字段,分别都是什么类型,哪个字段是自动增长 ...