<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% List<String> list1 = null; List<String> list2 = new ArrayList<String>(); list2.add("aaaaa"); List<String> list3 = new ArrayList<String>(); // int a; // 当没有给数组变量赋值的时候会报错(本地变量没有被初始化) int[] a = null; int[] b = new int[3]; int[] c = {}; request.setAttribute("list1", list1); request.setAttribute("list2", list2); request.setAttribute("list3", list3); request.setAttribute("array1", a); request.setAttribute("array2", b); request.setAttribute("array3", c); %> list1: ${empty list1 }<br> <!-- true --> list2: ${empty list2 }<br> <!-- false --> list3: ${empty list3 }<br> <!-- 返回true, 只new一个集合对象不调用add方法对EL表达式来说此集合是空的 --> array1: ${empty array1 }<br> <!-- true --> array2: ${empty array2 }<br> <!-- false --> array3: ${empty array3 }<br> <!-- 返回false, 声明一个空数组对象对EL表达式来说是有值的 --> </body> </html>