title: How to access List<> using c:forEach?
body: <p>In my 1st servlet where i generate List is as follows</p>
  
  <pre><code>List&lt;Image&gt; imageId = imageDAO.listNames(image);
  
  request.setAttribute("imageId", imageId);
  
  //Redirect it to home page
  request.getRequestDispatcher("/webplugin/jsp/profile/photos.jsp").forward(request, response);
  </code></pre>
  
  <p>which gets list of <code>imageId</code> to be displayed in JSP with help of <code>c:forEach</code></p>
  
  <pre><code>&lt;c:forEach items="${imageId}" var="image"&gt;
      &lt;img src="Photos/${image.photoid}"&gt;
  &lt;/c:forEach&gt;
  </code></pre>
  
  <p>I have a Image bean class which has photoid as its properties </p>
  
  <p>in second servlet which is mapped to <code>Photos</code> url-pattern i bring each photo.</p>
  
  <p>Problem:</p>
  
  <ol>
  <li>I am getting same image iterated over no of times which is equal to number of items in <code>imageId</code> list . Suppose imageId has five imageid's in its List then the same image is showed in my JSP for five times. How to retreive each <code>id</code> from it?</li>
  </ol>
  
  <p>EDIT: This is my imageDAO.listNames() method to get photoid is there problem while retreiving images and putting it in <code>List&lt;Image&gt;</code> </p>
  
  <pre><code>public List&lt;Image&gt; listNames(Image image) throws IllegalArgumentException, SQLException, ClassNotFoundException {
  
      Connection connection = null;
      PreparedStatement preparedStatement = null;
      ResultSet resultset = null;
      Database database = new Database();
      List&lt;Image&gt; list = new ArrayList&lt;Image&gt;();
  
      try {
  
          connection = database.openConnection();
          preparedStatement = connection.prepareStatement(SQL_GET_PHOTOID);                  
          preparedStatement.setLong(1, image.getUserid());
          resultset = preparedStatement.executeQuery();
  
          while(resultset.next()) {
              image.setPhotoid(resultset.getString(1));
              list.add(image);
          }
  
      } catch (SQLException e) {
          throw new SQLException(e);
      } finally {
          close(connection, preparedStatement, resultset);
      }
      return list;
  }
  </code></pre>