在使用idea中的maven-webapp骨架创建web项目时,我的web.xml文件头默认为
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
之初,配置Spring前端控制器,全局参数…等等,标签报红,但这并不影响项目的正常运行,因此也没换成
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
但是,在处理SpringMVC请求去获取集合类型参数时,使用了${pageContext.request.contextPath} 表达式,比如下面
<script src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
<script>
var userList = new Array();
userList.push({name:"zhangsan",age:23});
userList.push({name:"lisi",age:25});
$.ajax({
type:"post",
url:"${pageContext.request.contextPath}/user/success9",
data:JSON.stringify(userList),
contentType:"application/json;charset=utf-8"
});
</script>
报错如下
???难道使我js路径写的有问题?仔细检查并没有,此时idea控制台并没有报错详细信息。
再打开f12
再把xml文件头改成上面那个,就好了…这里的version应该在2.4以上,因此在使用EL表达式时,web.xml的头版本应该注意。
觉得有用不如进入我的Github博客留个言吧,谢谢支持!