Java 如何比较JSTL中的整数值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20189386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:51:38  来源:igfitidea点击:

How to compare integer value in JSTL

javajspjstl

提问by user2142786

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

嗨,我正在尝试比较 jstl 中的两个整数值,即使该语句为真,它也会返回结果 false。

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

输出为:4 HELLLOOOOOOO

回答by Masudul

You missed EL symbol ${}, Try,

你错过了 EL 符号${},试试吧,

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


   .....
   <c:when test = "${noc eq num}">
   .........

回答by Foolish

 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

此代码给出输出:4 hiiiiiiiiiiiii 4 HELLLOOOOOOO

回答by Zigri2612

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>