• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL + if statement

 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please folks, help me here:

If we have this:

<%@ taglib prefix="/WEB-INF/tlds/core.tld" uri="c" %>
<% int result = 1; %>
<c:if test="${2>1}" var="result"></c:if>
Result: ${result}

According to the mock tool�s answer, it would be "Result: true".

My question is..is that correct even if it�s a "int" primitive type?

Tks.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Felipe Pittella:
Please folks, help me here:

If we have this:

<%@ taglib prefix="/WEB-INF/tlds/core.tld" uri="c" %>
<% int result = 1; %>
<c:if test="${2>1}" var="result"></c:if>
Result: ${result}

According to the mock tool�s answer, it would be "Result: true".

My question is..is that correct even if it�s a "int" primitive type?

Tks.



In the abve if statement The var="result" will create a page scope variable (attribute). In the EL ${result} the value stored in page scope variable is accessed. The int result is not used anyway.

Thanks
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hun, right got it.

But ins�t the <%int result=0%> also delclared in page scope as well?
Same scope, same name?

Tks.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

<%int result=0; %> is not a attribute, it is just variable in the _jspService method, you can not access these variables throu EL. The result in the if statement is like the attribute set by the pageContext.setAttribute(String,Object) method.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic