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 ...
随机推荐
- POST提交表单时EnType设置问题
POST提交表单时EnType设置问题 首先知道enctype这个属性管理的是表单的MIME编码.共有三个值可选: 1.application/x-www-form-urlencoded 2.mult ...
- tomcat启动超时_tomcat was unable to start within
参考: http://jingyan.baidu.com/article/64d05a025c9969de55f73b23.html 首先,你得确认下你的数据库连接,尤其是在多个服务器之间转换或者服务 ...
- GFS中文翻译
Google文件系统 GFS是一个可扩展的分布式文件系统,用于大型的.分布式的.对大量数据进行访问的应用.它运行于廉价的普通硬件上,但可以提供容错功能.它可以给大量的用户提供总体性能较高的服务. 1. ...
- 从头入手jenkins
前段时间项目处在测试阶段.5个测试妹子围着转,你不知道幸福的啊. 项目一共有开发.测试.生产三个环境,每次打包要切换分支代码,然后使用Xcode打包,然后生成ipa,再上传到蒲公英或者fir给测试妹子 ...
- 无法获取 vmci 驱动程序版本: 句柄无效
https://jingyan.baidu.com/article/a3a3f811ea5d2a8da2eb8aa1.html 将 vmci0.present = "TURE" 改 ...
- Codeforces Round #506 (Div. 3) D. Concatenated Multiples
D. Concatenated Multiples You are given an array aa, consisting of nn positive integers. Let's call ...
- jetty安装、配置、优化
)Jetty: 作用:Jetty 是一个开源的servlet容器,它为基于Java的web内容,例如JSP和servlet提供运行环境. 特性:易用性,可扩展性,易嵌入性 2) Jetty安装: t ...
- Java学习笔记22(List接口)
List接口继承自Collection接口,自身具有三大特点: 1.有序集合:存入和取出的顺序一致: 2.此接口的用户可以对每个元素插入位置进行精确控制:可以通过索引操作元素 3.可以存储重复元素 L ...
- linux 安装crontab执行定时任务
转载:https://www.cnblogs.com/xiaoluo501395377/archive/2013/04/06/3002602.html http://yangqijun.iteye.c ...
- 转:C++ 类的静态成员详细讲解
在C++中,静态成员是属于整个类的而不是某个对象,静态成员变量只存储一份供所有对象共用.所以在所有对象中都可以共享它.使用静态成员变量实现多个对象之间的数据共享不会破坏隐藏的原则,保证了安全性还可以节 ...