使用使用IDEA编写编写jsp时时EL表达式不起作用的问题及解决方法表达式不起作用的问题及解决方法
在使用IDEA开发maven+springMVC项目时遇到不加载EL表达式的问题,怎么处理呢?下面小编给大家带来了实现代码,一
起看看吧
加载如下JSP代码:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<c:forEach items="${userList }" var="lists">
<h3>${lists.username }</h3>
<h3>${lists.password }</h3>
</c:forEach>
</body>
</html>
显示结果为:
${lists.username }
${lists.password }
按平常来说引入JSTL包理应执行EL表达式,但却没有…
解决方法:解决方法:
在JSP开头添加
<%@page isELIgnored="false"%>
isELIgnored是指是否忽略EL表达式
isELIgnored 属性JSP 2.0 新引入的属性,在只支持 JSP 1.2 及早期版本的服务器中,使用这项属性是不合法的。这个属性的
默认值依赖于 Web 应用所使用的 web.xml 的版本。如果 web.xml 指定 servlet 2.3(对应JSP 1.2)或更早版本,默认值为
true(但变更默认值依旧是合法的,JSP 2.0 兼容的服务器中都允许使用这项属性,不管 web.xml 的版本如何)
查看Servlet版本
打开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" >
按住Ctrl点击链接,到78行左右就可以看到一段注释
<!--
This is the XML DTD for the Servlet 2.3 deployment descriptor.
All Servlet 2.3 deployment descriptors must include a DOCTYPE
of the following form:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
-->
翻译一下就是
“这是Servlet 2.3部署描述符的XML DTD。所有的Servlet 2.3部署描述符必须包含于下面的DOCTYPE”
很明显这就是Servlet 2.3版本
所以
isELIgnored的属性默认为true…
如果还有问题?
建议在maven dependencies添加引用包(个人感觉这个不是问题,加不加一样…)
评论0