• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JSTL + if statement

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic