下面為index.jsp中的代碼:
1
<logic:notPresent name="users">
2
notpresent
3
</logic:notPresent>
4
<logic:notEmpty name="users">
5
notempty
6
</logic:notEmpty>
7
<logic:empty name="users">
8
empty
9
</logic:empty>
10
<logic:present name="users">
11
present
12
</logic:present>

2

3

4

5

6

7

8

9

10

11

12

當(dāng)?shù)谝淮卧L問該JSP的時(shí)候,由于users沒有定義,并且也不在page,request,session,application任何一個(gè)作用域中,因此輸出的結(jié)果為notpresent,empty。
下面我們?cè)黾右粋€(gè)action,讓他在index.jsp之前執(zhí)行,然后再跳轉(zhuǎn)到index.jsp中,同時(shí)在該action的execute方法中增加如下代碼:
1
String userName = "";
2
request.setAttribute("users", userName);
3
return new ActionForward("/index.jsp");
4
這里將userName保存在request中,key為users,再將請(qǐng)求轉(zhuǎn)發(fā)至index.jsp中,但是userName的值為一個(gè)空字符串,轉(zhuǎn)發(fā)過后,輸出的值為:empty,present 
2

3

4

這里我們?cè)僮鲆淮胃膭?dòng),將action的execute方法中的代碼改為:
1
String userName = null;
2
request.setAttribute("users", userName);
3
return new ActionForward("/hello.jsp");
4
不同的是userName 不再為空字符串了,而是null值,當(dāng)轉(zhuǎn)發(fā)至index.jsp后,輸出的值為:notpresent,empty 。
2

3

4

對(duì)比這幾次改動(dòng),我們可以得出結(jié)論:
對(duì)于沒有在page,request,session,application中定義或者是沒有分配內(nèi)存空間(null值)的變量,這兩個(gè)標(biāo)記處理的方法是一致的,都會(huì)認(rèn)為此變量不存在(notpresent)或者為空(empty)。而對(duì)于空字符串""值,他們的處理就不一樣了,logic:present 標(biāo)記認(rèn)為空字符串仍然是存在的,也就是說,只要是引用了一塊內(nèi)存空間的變量,logic:present 就會(huì)返回present ;而logic:empty則認(rèn)為空字符串仍然為空,由此得出,在logic:empty看來,變量不僅僅要引用一塊內(nèi)存空間,而且該地址空間的值不能為空字符串,否則都認(rèn)為該變量為空,都會(huì)返回empty