title: how to get values from class to jsp using arraylist?
body: <p>hi i have some problem in retriving data from database using arraylist.i am only able to get the last entry of the column.here is my code any help is appreciated.thank you in advance.  </p>
  
  <p><strong>this is where iam fetching data from database</strong></p>
  
  <pre><code>VariableIntialization location = new VariableIntialization();
              HttpSession session = request.getSession();
            String sql = "SELECT * FROM country";
          Database db= new Database();
                            PreparedStatement pst = db.getConnection().prepareStatement(sql);
                           ResultSet i = pst.executeQuery();
  
                              while (i.next()) {
                                  String country_id = i.getString(1);
                                  String country = i.getString(2);
                              ArrayList&lt;String&gt; countries = new ArrayList&lt;String&gt;();
                                  countries.add(country);
                                  location.setcountry(countries);
                                  location.setcountry_id(country_id);
                              }
      session.setAttribute("deshopa_country", location);
                  response.sendRedirect("admin/stateadd.jsp");
  </code></pre>
  
  <p><strong>here is my .java class where data goes in to..</strong></p>
  
  <pre><code>package requirementlogic;
  
  import java.util.ArrayList;
  
  public class VariableIntialization {
      private ArrayList&lt;String&gt; content =new ArrayList&lt;String&gt;();
          public void setcountry(ArrayList&lt;String&gt; content)
                      {
                          this.content = content;
  
                      }
                   public ArrayList&lt;String&gt; getcountry() { return content; }
  }
  </code></pre>
  
  <p><strong>here is my jsp page where i want to display data</strong></p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %&gt;
   &lt;%@ page import = "requirementlogic.*"  %&gt;
   &lt;%@ page import = "java.util.ArrayList" %&gt;
        &lt;%VariableIntialization ds_country =(VariableIntialization)session.getAttribute("deshopa_country"); %&gt;
  
      &lt;% ArrayList&lt;String&gt; desham =new ArrayList&lt;String&gt;();
              desham = ds_country.getcountry();
  
  &lt;html&gt;
  &lt;body&gt;
  &lt;form method="get" action="../State" name="location" id="location"&gt;
  &lt;%if(session.getAttribute("deshopa_country") != null){ %&gt;
  &lt;div class="span2"&gt;&lt;select name="country_ref" id="country_ref" class="clear"&gt;
  &lt;%for(int i=0; i&lt;desham.size() ;i++){ %&gt;
  &lt;option&gt;&lt;%=desham.get(i)%&gt;&lt;/option&gt;
  
  &lt;%} %&gt;
  &lt;/select&gt;&lt;/div&gt;
  &lt;%} %&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>