In the following code, why it prints "LOGIC: EMPTY" on the console? I
expect to see "LOGIC: NOT EMPTY" since ss is not null, and it should
pass the test <logic:notEmpty name="ss">. What I am missing here?
Please advice. Thanks!!
<%
String ss = "JJ";
System.out.println("from jsp = " + ss);
%>
<%
if (ss == null)
System.out.println("SS = null");
else
System.out.println("SS != null");
%>
<logic:empty name="ss">
<% System.out.println("LOGIC: EMPTY " ); %>
</logic:empty>
<logic:notEmpty name="ss">
<% System.out.println("LOGIC: NOT EMPTY " ); %>
</logic:notEmpty>
<c:if test="ss != null}">
<% System.out.println("JSTL LOGIC: NOT EMPTY " ); %>
</c:if>
output
==========
[8/9/06 16:19:57:470 PDT] 7d42a949 SystemOut O from jsp = JJ
[8/9/06 16:19:57:470 PDT] 7d42a949 SystemOut O SS != null
[8/9/06 16:19:57:470 PDT] 7d42a949 SystemOut O LOGIC: EMPTY
[8/9/06 16:19:57:470 PDT] 7d42a949 SystemOut O JSTL LOGIC: NOT
EMPTY
Tobias Schierge - 10 Aug 2006 09:18 GMT
Hi,
> <%
> String ss = "JJ";
[quoted text clipped - 17 lines]
> <% System.out.println("JSTL LOGIC: NOT EMPTY " ); %>
> </c:if>
You are mixing references to bean variables and locally declared variables.
Please get some deeper understanding of the stuff. Another Advice would be
to ban all scriptlets from JSP to avoid lots of trouble.
try: request.setAttribute("ss","jj"); or
pageContext.setAttribute("ss","jj");
Regards,
Tobias