下面為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

當第一次訪問該JSP的時候,由于users沒有定義,并且也不在page,request,session,application任何一個作用域中,因此輸出的結果為notpresent,empty。
下面我們增加一個action,讓他在index.jsp之前執行,然后再跳轉到index.jsp中,同時在該action的execute方法中增加如下代碼:
1
String userName = "";
2
request.setAttribute("users", userName);
3
return new ActionForward("/index.jsp");
4
這里將userName保存在request中,key為users,再將請求轉發至index.jsp中,但是userName的值為一個空字符串,轉發過后,輸出的值為:empty,present 
2

3

4

這里我們再做一次改動,將action的execute方法中的代碼改為:
1
String userName = null;
2
request.setAttribute("users", userName);
3
return new ActionForward("/hello.jsp");
4
不同的是userName 不再為空字符串了,而是null值,當轉發至index.jsp后,輸出的值為:notpresent,empty 。
2

3

4

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