jsp中引入jquery报错:Failed to load resource: the server responded with a status of 404 (Not Found)
问题描述:
今天自己在搭建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)的更多相关文章
- 上传图片报错-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" ...
- 报错解决——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 ...
- 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) 报错情况:图标加载失败 原因分析:路径错误 ...
- 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 ...
- 待解决: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 ()
- 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 () 但是其他页面正常显示: 原因: 浏览器看一下: ...
- Failed to load resource: the server responded with a status of 404 ()
今天遇到了一个一开始感觉很莫名其妙的报错 在编写页面的时候把原先写在html页面里的js代码单独拿出来做成一个JavaScriptUtil文件,放在了和html页面同一个目录下.运行之后在对应的页面c ...
- 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文件找不到 ...
- 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 ...
随机推荐
- learning at commad AT+CPSI
[Purpose] Learning how to get mobile network info [Eevironment] Shell terminal, base on gcom command ...
- node代理服务器
var express = require('express');var request = require('request');var app = express();var _URL = 'ht ...
- hdu1695
题解: 莫比乌斯反演 设f[i]=Σgcd(i,j)%z==0 则f[i]=Σgcd(i,j)==zd 成莫比乌斯反演关系 代码: #include<cstdio> #include< ...
- HTML编辑笔记4
1.CSS(层叠样式表) 2.CSS语法 选择器{ 属性名1:属性值1: 属性名2:属性值2: } 3.引用CSS的三种方式 第一种:行内样式 例:<a style="color:re ...
- 使用DDMS查看设备内的文件系统
system文件系统存储了一些系统相关的文件 system/app里面是系统自带的应用程序 system/fonts里面存放的是系统自带的字体 system/frameworks里面存放的是系统的一些 ...
- 多线程处理慢sql查询小笔记~
多线程处理慢sql查询以及List(Array)的拆分 系统数据量不大,但是访问速度特别慢,使用多线程优化一下!!! 优化结果:访问时间缩短了十几秒 25s --> 8s 一.List的拆分: ...
- .net core 之Hangfire任务调度
Hangfire可用作任务调度,类似延迟任务.队列任务.批量任务和定时任务等. 一.nuget Hangfire包 找到Hangfire.AspNetCore和Hangfire.SqlServer包, ...
- hustoj 管理员和后台设置
之前用过hustoj 的livecd版本,觉得有一些小问题,所以从头到尾搭建.主要包含的过程包括: 安装ubuntu系统 搭建hustoj 管理员和后台资源建设 本文介绍如何在搭建好hustoj的基础 ...
- leetcode python 004
## 已知l1,l2均为升序数组,## 在两数组l1,l2中寻找第n位数,## 两数组中位数中,前者大于后者,说明后者中位数以下的成员必定在真正中位数之下## 可以将其剔除,剔除a个元素后的两 ...
- python笔记7-if中的is ;in ;not搭配用法
names="111 222 333" print("111" in names)#返回的是True,用in返回的是布尔值in在里面 print("1 ...