今天做項目遇到一個棘手的問題,檢查了半天的代碼最後才發現是EL表達式不生效,因爲根本沒有想過EL表達式也會出問題。
通過在網上查閱資料後才知道了解決的方法,以下內容大部分轉載至CSDN博主「upupfeng」的文章內容,原文鏈接爲:https://blog.csdn.net/ifenggege/article/details/83002123
問題描述:
el表達式不進行解析,直接輸出${}在頁面上
解決方案:
第一種:
Servlet2.3默認是不支持EL表達式的,Servlet2.4默認支持,可以修改web.xml中的web-app標籤下的version屬性爲2.4以上即可解決
將如下代碼替換掉你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_4_0.xsd"
version="4.0"
metadata-complete="true">
</web-app>
第二種:
在需要使用el表達式的頁面加上指令<%@ page isELIgnored=“false” %>
以上兩種方法親測都有效,建議採用第一種!