今天做项目遇到一个棘手的问题,检查了半天的代码最后才发现是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” %>
以上两种方法亲测都有效,建议采用第一种!