title: How to add JavaBeans to an ArrayList in the session?
body: <p>This is an exercise from our Professor. I am kinda stuck. First he wants us to Store a company name and price in a JavaBean we will create – one price and company per instance. This means we require three bean instances.</p>
  
  <p>Please see, he wants us to hard-code in three companies and prices using the above method.</p>
  
  <p>Then, He wants us to Add the JavaBeans to an ArrayList in the session &amp; Forward to a JSP for display.</p>
  
  <p>This is what I am upto now,</p>
  
  <pre><code>    &lt;jsp:useBean id="company1" class="beans.Invoice" scope="session"&gt;&lt;/jsp:useBean&gt;
      &lt;jsp:useBean id="company2" class="beans.Invoice" scope="session"&gt;&lt;/jsp:useBean&gt;
      &lt;jsp:useBean id="company3" class="beans.Invoice" scope="session"&gt;&lt;/jsp:useBean&gt;
  
      &lt;jsp:setProperty property="companyName" name="company1" value="Telco" /&gt;
      &lt;jsp:setProperty property="price" name="company1" value="23" /&gt;
  
      &lt;jsp:setProperty property="companyName" name="company2" value="Telcos" /&gt;
      &lt;jsp:setProperty property="price" name="company2" value="25" /&gt;
  
      &lt;jsp:setProperty property="companyName" name="company3" value="Telcoi" /&gt;
      &lt;jsp:setProperty property="price" name="company3" value="27" /&gt;
  </code></pre>
  
  <p>On the same jsp, I am doing this,</p>
  
  <pre><code>&lt;%
          ArrayList&lt;Object&gt; disp = new ArrayList();
          disp.add(company1);
          disp.add(company2);
          disp.add(company3);
  
          HttpSession sess = request.getSession();
          session.setAttribute("disp", disp);
  
  %&gt;
  </code></pre>
  
  <p>Then on next JSP as required by him, I am doing this,</p>
  
  <pre><code>   &lt;%
          ArrayList&lt;String&gt; list = (ArrayList&lt;String&gt;) request.getSession()
                  .getAttribute("disp");
  
          for (String r : list) {
              out.println(r);
          }
      %&gt;
  </code></pre>
  
  <p>Here is the error I get</p>
  
  <pre><code>java.lang.ClassCastException: beans.Invoice cannot be cast to java.lang.String
  </code></pre>
  
  <p>Where I might be doing wrong?</p>