SpringMVC在调用静态资源时出现
Uncaught ReferenceError: $ is not defined at response.jsp:9

或者提示GET http://localhost:8080/springmvc_day02_01_response_war/js/jquery.min.js net::ERR_ABORTED 404
解决方法:
1、这是由于被DispatcherServlet拦截器拦截,需要做出静态资源声明:
<mvc:resources location="/img/" mapping="/img/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/css/" mapping="/css/**"/>
springmvc版本不一样,location跟mapping可能需要反过来写,反正我这样是可以的
2、如果上述步骤后依然提示错误,则可以在右侧工具栏中maven->lifecycle下执行clean命令,
运行结束之后再执行install命令即可。
本文详细介绍了在使用SpringMVC框架时遇到的静态资源加载失败问题,包括JavaScript未定义错误及404错误,并提供了两种解决方案:一是通过配置静态资源路径;二是执行Maven的clean和install命令。
1459

被折叠的 条评论
为什么被折叠?



