how to pass an initialising variable used in a for loop into a scriptlet to get the values iterated ?

Posted on 2006-05-23
Last Modified: 2011-09-20
<%      for (int _i0 = 0; ; ) { %>
               <c:set var ="_i0" value ="${_i0 + 1}" ></c:set>
                      <c:set var="_p0_7" value="<%=PolicyQuery.getINSURED_ZIP(_i0)%>"></c:set>//here s te pbm.
<%} %>
hi i am getting error saying that _i0 could not be resolved.

i tried with the below added code too :
<%      for (int _i0 = 0; ; ) { %>
          <c:set var="_i0" value="<%=_i0%>" />
              <c:set var ="_i0" value ="${_i0 + 1}" ></c:set>
                      <c:set var="_p0_7" value="<%=PolicyQuery.getINSURED_ZIP(_i0)%>"></c:set>
<%} %>

can i get an immediate reply , its very urgent to resolve this ..,
Question by:mali_ini
    LVL 14

    Expert Comment

    You cant put a scriptlet inside the jstl tag property, it should be in the content of the tag.
    <c:set var="_i0"><%=_i0%></c:set>
    LVL 14

    Accepted Solution

    You can use jstl forEach tag for looping
    <c:forEach begin="1" end="10" var="_i0">
        <c:set var="_p0_7"><%=PolicyQuery.getINSURED_ZIP((Integer) pageContext.getAttribute("_i0") )%></c:set>
    LVL 27

    Assisted Solution

    Try it this way.
    <%      for (int _i0 = 0; ; ) { %>
                 <c:set var ="_i0" value ="<%=_i0 + 1%>" ></c:set>
                      Long _i0 = (Long)pageContext.getAttribute("_i0");
                         <c:set var="_p0_7" value="<%=PolicyQuery.getINSURED_ZIP(_i0.intValue())%>"></c:set>
    <%} %>

    or maybe better  try  

    <%      for (int _i0 = 0; ; ) { %>
                         <c:set var="_p0_7" value="<%=PolicyQuery.getINSURED_ZIP(_i0 + 1)%>"></c:set>
    <%} %>

    But  maybe better to go with forEach as boonleng suggested above  and as my last post at    


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
    OfficeMate Freezes on login or does not load after login credentials are input.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now