<logic:notPresent name="users">
notpresent
</logic:notPresent>
<logic:notEmpty name="users">
notempty
</logic:notEmpty>
<logic:empty name="users">
empty
</logic:empty>
<logic:present name="users">
present
</logic:present>
String userName = "";
request.setAttribute("users", userName);
return new ActionForward("/index.jsp");
String userName = null;
request.setAttribute("users", userName);
return new ActionForward("/hello.jsp");
不同的是userName 不再为空字符串了,而是null值,当转发至index.jsp后,输出的值为:notpresent,empty 。
对比这几次改动,我们可以得出结论:
对于没有在page,request,session,application中定义或者是没有分配内存空间(null值)的变量,这两个标记处理的方法是一致的,都会认为此变量不存在(notpresent)或者为空(empty)。
而对于空字符串""值,他们的处理就不一样了,
logic:present 标记认为空字符串仍然是存在的,也就是说,只要是引用了一块内存空间的变量,logic:present 就会返回present ;
而logic:empty则认为空字符串仍然为空,由此得出,在logic:empty看来,变量不仅仅要引用一块内存空间,而且该地址空间的值不能为空字符串,否则都认为该变量为空,都会返回empty
Tags: taglib logic notEmpty notPresent struts
原创文章如转载,请注明:转载自:飞扬部落编程仓库 : http://www.busfly.net/csdn/
本文链接地址:http://www.busfly.net/csdn/post/struts-logic-notEmpty-notPresent.html
如果你喜欢本文,请顶一下,支持我,你的支持是我继续发好文章的最大动力。谢谢。
好东西需要分享,快把本文发给你的朋友吧~!~