Note that there are some explanatory texts on larger screens.

plurals
  1. PONot getting the proper size of an ArrayList in JSP
    text
    copied!<p>I'm having trouble getting the right number of elements in the ArrayList <code>alt</code> in the JSP page below. When I view the JSP it shows the size is 1 (<code>&lt;%=alt.size()%&gt;</code>) when it should be 3; I think I'm adding that method to the array in the generator class, so I don't understand why it's showing 1.</p> <p>This is my jsp page:</p> <pre><code>&lt;% ArrayList&lt;Alert&gt; a = AlertGenerator.getAlert(); pageContext.setAttribute("alt", a); %&gt; &lt;c:forEach var="alert" items="${alt}" varStatus="status" &gt; &lt;p&gt;You have &lt;%=alt.size()%&gt; Active Alert(s)&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#" class="linkthree"&gt;${alert.alert1}&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="linkthree"&gt;${alert.alert2}&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="linkthree"&gt;${alert.alert3}&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/c:forEach&gt; </code></pre> <p>This is class that generates the alerts:</p> <pre><code>package com.cg.mock; import java.util.ArrayList; public class AlertGenerator { public static ArrayList&lt;Alert&gt; getAlert() { ArrayList&lt;Alert&gt; alt = new ArrayList&lt;Alert&gt;(); alt.add(new Alert("alert1","alert2","alert3")); return alt; } } </code></pre> <p>This is my bean class:</p> <pre><code>package com.cg.mock; public class Alert { String alert1; String alert2; String alert3; public Alert(String alert1, String alert2,String alert3) { super(); this.alert1 = alert1; this.alert2 = alert2; this.alert3 = alert3; } public String getAlert1() { return alert1; } public void setAlert1(String alert1) { this.alert1 = alert1; } public String getAlert2() { return alert2; } public void setAlert2(String alert2) { this.alert2 = alert2; } public String getAlert3() { return alert3; } public void setAlert3(String alert3) { this.alert3 = alert3; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload