title: Want to retrieve data from database using servlets and display it in jsp
body: <p>I want to retrieve data from database using servlet and show it into a jsp file ,but what is retrieved is only the first row of the table.I want to be retrieved all rows.Could anyone help me? Thanks,and here is my code:</p>
  
  <p>Servlet:</p>
  
  <pre><code>    try{
  
          DBConnection connection = new DBConnection();
          Connection con = connection.Connect();
          ResultSet rs;
          Statement st = con.createStatement();
          java.sql.PreparedStatement ps=con.prepareStatement("SELECT Nume,Descriere,Ingrediente,Mod_preparare,Imagini,Total_grasimi,Total_carbohidrati,Total_proteine,Total_calorii FROM reteta");
          rs=ps.executeQuery();
  
          while(rs.next()){
              //name
              String Nume = rs.getString("Nume");
              request.setAttribute("Nume",Nume);
  
              //descripton
              String Descriere = rs.getString("Descriere");
              request.setAttribute("Descriere",Descriere);
  
              //images
              String Imagini = rs.getString("Imagini");
              request.setAttribute("Imagini",Imagini);
  
  
         request.getRequestDispatcher("/retete.jsp").forward(request, response);
  
  
          }
  
      rs.close();
      st.close();
      con.close();
      }
      catch (Exception e2)
      {
        e2.printStackTrace();
      }
  
      finally
      {
        out.close();
      }
  }
  </code></pre>
  
  <p>Jsp:</p>
  
  <pre><code>        &lt;a href="images/{Imagini} " class="gall_item"&gt;&lt;img src="images/${Imagini}" alt=""&gt;&lt;/a&gt;
          &lt;div class="gall_bot"&gt;
          &lt;div class="text1"&gt;&lt;a href="#"&gt;${Nume} &lt;/a&gt;&lt;/div&gt;
          ${Descriere} 
          &lt;br&gt;
          &lt;button type = "submit" class = "btn" &gt;more&lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>