在使用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添加引用包(個人感覺這個不是問題,加不加一樣...)
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
End......
感謝查看 ≧◇≦
歡迎大家一起交流學習~~~