在jsp页面中使用el表达式,结果el表达式失效,解决办法如下。
方法一:
在jsp页面上添加如下标签
<%@ page isELIgnored="false" %>
该设置代表在本jsp中使用el表达式,可以解析其中的值。若isELIgnored设置为true,代表在本页不使用el表达式,当做字符串解析出来显示。此时,el表达式正常工作,显示正常。
方法二:
在web.xml中配置
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<!-- <el-ignored>默认为true,设置为false即可 -->
<el-ignored>false</el-ignored>
</jsp-property-group>
</jsp-config>
原因:官方解释
If isELIgnored is true, EL expressions are ignored when they appear in static text or tag attributes. If it is false, EL expressions are evaluated
by the container only if the attribute has rtexprvalue set to true or the expression is a deferred expression.
The default value of isELIgnored varies depending on the version of the web application deployment descriptor. The default mode for JSP pages
delivered with a Servlet 2.4 descriptor is to evaluate EL expressions; this automatically provides the default that most applications want. The default mode for JSP pages delivered using a descriptor from Servlet 2.3 or before is to ignore EL expressions; this provides backward compatibility.
大概意思也就是说servlet2.3及以前的版本默认是true,不解析el表达式,servlet2.4及更新的版本默认为false,解析el表达式。