title: displaying a list of entities in jsp file by using java
body: <p>I am trying to display list of entities in a .jsp file, but I this error:</p>
  
  <pre><code>Unable to compile class for JSP: 
  
  An error occurred at line: 28 in the jsp file: /guestbook.jsp
  Can only iterate over an array or an instance of java.lang.Iterable
  25:     &lt;/tr&gt;
  26:     &lt;tr&gt;
  27:     &lt;%
  28:         for (Entity drugtarget : "${drugtargets}") {
  29:         %&gt;
  30:     &lt;td&gt; 
  31:     &lt;%
  </code></pre>
  
  <p>Here is my query from servlet class:</p>
  
  <pre><code>DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  Query query = new Query("DrugTarget").addSort("drug", Query.SortDirection.DESCENDING);
  List&lt;Entity&gt; drugtargets = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(10));
  
  req.setAttribute("drugtargets", drugtargets);
  </code></pre>
  
  <p>And this is how I send drugtargets to jsp file:</p>
  
  <pre><code>String url = "/guestbook.jsp";
  ServletContext sc = getServletContext();
  RequestDispatcher rd = sc.getRequestDispatcher(url);
  try {
      rd.forward(req, resp);
  } catch (ServletException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>Finally here is how I write jsp part:</p>
  
  <pre><code>&lt;table border="1"&gt;
    &lt;tr&gt;
      &lt;th&gt;Drug Names&lt;/th&gt;
      &lt;th&gt;Target Names&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;%
        for (Entity drugtarget : "${drugtargets}") {
      %&gt;
      &lt;td&gt; 
      &lt;%
        pageContext.setAttribute("drug_content",
                                  drugtarget.getProperty("drug"));
      %&gt;
      ${fn:escapeXml(drug_content)}
      &lt;/td&gt;
      &lt;td&gt;
      &lt;%
        pageContext.setAttribute("target_content",
                                  drugtarget.getProperty("target"));
      %&gt;
      ${fn:escapeXml(target_content)}
      &lt;/td&gt;   
      &lt;%
        }
      %&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I think I'm making a syntax mistake, but I'm not sure. I checked some examples and the same way (to send list of entities from servlet to jsp and to reach entities in jsp file) was used. How can I resolve this error?</p>