0

Hi i'm trying to compare two integer values in jstl it is returning the result false even if the statement is true.

here is my code

 String numofcell=(String)request.getAttribute("numberofcell"); 
 int noc = Integer.parseInt(numofcell);
int num = 4;

<c:choose>
    <c:when test = "${noc eq num}">
        <%=noc%>
        hiiiiiiiiiiiii
    </c:when>
    <c:otherwise>
        <%=noc%>
        HELLLOOOOOOO 
    </c:otherwise>
</c:choose>

output is : 4 HELLLOOOOOOO

user2142786
  • 1,484
  • 9
  • 41
  • 74

3 Answers3

1

You missed EL symbol ${}, Try,

 <c:set var="noc" value="<%=noc%>"/>     
  <c:set var="num" value="<%=num%>"/>


   .....
   <c:when test = "${noc eq num}">
   .........
Masudul
  • 21,823
  • 5
  • 43
  • 58
0
 String numofcell="4";
 int noc = Integer.parseInt(numofcell);
int num = 4;

<c:choose>
    <c:when test = "noc eq num">
        <%=noc%>
        hiiiiiiiiiiiii
    </c:when>
    <c:otherwise>
        <%=noc%>
        HELLLOOOOOOO 
    </c:otherwise>
</c:choose>

This code giving output : 4 hiiiiiiiiiiiii 4 HELLLOOOOOOO

Foolish
  • 3,952
  • 33
  • 46
0
String numofcell="4";
 int noc = Integer.parseInt(numofcell);
int num = 4;
pageContext.setAttribute("noc",noc);
pageContext.setAttribute("num",num);

<c:choose>
    <c:when test = "${noc eq num}">
        <%=noc%>
        hiiiiiiiiiiiii
    </c:when>
    <c:otherwise>
        <%=noc%>
        HELLLOOOOOOO 
    </c:otherwise>
</c:choose>
Zigri2612
  • 2,279
  • 21
  • 33