问题描述:

  今天自己在搭建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. linux 基础储备

    ls命令是Linux下最常用的命令之一,ls跟dos下的dir命令是一样的都是用来列出目录下的文件,下面我们就来一起看看ls的用法ls /home 这个命令不但可以添加用户到系统,而且可以默认为新用户 ...

  2. Java实现将数字转为大写汉字

    public class Int2Big { static String int2big(int src) { final String num[] = {"零", "壹 ...

  3. vue-5-列表渲染

    一个数组的v-for<ul id="example-1"> <li v-for="item in items"> {{ item.mes ...

  4. pdf及word文档的读取 pyPDF2,docx

    #!python3 #-*- coding:utf8 -*- #PyPDF2可能会打不开某些pdf文档,也不能提取图片,图表或者其他媒介从PDF文件中.但是它能提取文本从PDF中,转化为字符. imp ...

  5. java动手动脑2

    仔细阅读示例: EnumTest.java,运行它,分析运行结果? 你能得到什么结论?你掌握了枚举类型的基本用法了吗? 运行结果: 第一个false是判断s和t是否引用同一个对象,第二个false是判 ...

  6. 2.1FTP的简单传输

    第一个简单的FTP传输实例 from ftplib import FTP nonpassive = False filename = 'new_1.py' dirname = '.' sitename ...

  7. 1.3用socketserver创建服务器

    socket服务器代码 # -*- coding: utf-8 -*-import socketserver,time myHost = '' myPort = 50007 def now(): #返 ...

  8. 文件上传FormData

    <div class="modal-dialog"> <div class="modal-content"> <div class ...

  9. table-cell 布局

    table-cell能实现段落文字相对于div的垂直居中: 将div设置为display:table-cell; *display:inline-block;text-align:center; ve ...

  10. Java基础-变量常量

    变量 内存中的一小块区域,需要变量名来访问 变量的命名: 变量类型 变量名=变量值 例:String stuName= "wangwei"; java中的所有标点符号都是英文的 变 ...