最近在学习jsp页面的时候,碰到关于el表达式不能加载的问题,一开始几经波折,以为是servlet或者是jstl标签出了问题。后来才发现是因为web项目中的web.xml中的servlet的版本过低导致的。
下面给出解决办法:
<!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版本,查了一下,默认情况下,Servlet2.3/jsp1.2默认是不支持el表达式。
这里给出两种解决办法:
1.第一种方式,是直接在jsp文件头部标签前加入:isELIgnored="false"
<%@ page contentType=“text/html;charset=UTF-8” language=“java” isELIgnored=“false” %>
表示强制性的不忽略el表达式格式,重新测试,成功显示数据.
2.第二种方式就是使用servlet的更高版本,比如我直接将web.xml改成2.5版本:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
</web-app>
此时,不需要设置 isELIgnored=“false” 因为此版本已经默认支持el表达式了.