jsp页面的EL表达式失效(被忽略)。
错误如下,使用${pageContext.request.contextPath}获取项目的路径失败,EL表达式没有解析。
JSP页面代码:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>所有学生信息</title>
<script src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script>
<script src="${pageContext.request.contextPath}/js/index.js"></script>
</head>
<body>
<table id="table1">
</table>
</body>
</html>
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 xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
可能的原因:
IDEA使用的webapp骨架时候,自动生成的web.xml文件的web-app版本是2.3的,导致EL表达式混乱,因为EL表达式是2.4以上版本才支持的。
解决方法一:
在jsp页面上加上:
<%@ page isELIgnored="false" %>
设置jsp页面不忽略EL表达式,这个设置的优先级最高。
这种方式是可以解决的,但是每次新建jsp页面都要加上这一段代码,当然可以修改jsp页面模板。
解决方法二:
把上面的web.xml的信息修改成如下的。
修改web.xml配置信息:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="false">
同样每次都要修改的话很麻烦,也可以直接修改创建项目时用到的模板,maven-archetype-webapp的jar包。
可以参考:修改maven webAPP 模板