title: How to display list of Date from servlet in selector tag in jsp page
body: <p>I am trying to dynamically generate a list of dates without duplicates in JSP to display in a selector tag.</p>
  
  <p>In my servlet class:</p>
  
  <pre><code>query = " SELECT * FROM visits";
  prepStatement = connection.prepareStatement(query);
  
  results = prepStatement.executeQuery();
  Set&lt;Date&gt; vdates = new HashSet&lt;&gt;();
  while(results.next()){
      vdates.add(results.getDate("date"));                
  }
  Date[] dates = vdates.toArray(new Date[vdates.size()]);
  out.println(vdates);
  request.setAttribute("dates", dates);
  RequestDispatcher dispatcher = request.getRequestDispatcher("/js/selectorJSP.jsp");
  dispatcher.forward(request, response);
  </code></pre>
  
  <p>In my selectorJSP file:</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;JSP Selector Page&lt;/title&gt;
      &lt;script src="js/jquery-2.1.4.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Hello World!&lt;/h1&gt;
      &lt;select&gt;
          &lt;option value="AllRecords"&gt;${dates[0]}&lt;/option&gt;
      &lt;/select&gt;
      &lt;input type="button" onclick="" value="Download"&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The result is that it just shows an empty field, I am trying to show one to make sure it works and make a loop to show all available dates in selector but not available.</p>