title: Dynamic database table display using Jstl
body: <p>I am trying to display database data using JSTL like this:</p>
  
  <p>My dao;</p>
  
  <pre><code>public ArrayList getStudentFirstName(){
          ArrayList v = new ArrayList();
          Connection conn;
          try{
           conn =  db.getDbConnection();
           String sql = "select STU_FIRST_NAME, STU_MIDDLE_NAME, LAST_NAME from college_students_master";
           PreparedStatement ps = conn.prepareStatement(sql);
           ResultSet rs = ps.executeQuery();
           while(rs.next()){
               String firstname = rs.getString("STU_FIRST_NAME");
               String middlename = rs.getString("STU_MIDDLE_NAME");
               String lastname = rs.getString("LAST_NAME");
               v.add(firstname);
               v.add(middlename);
               v.add(lastname);
           }
          }catch(Exception asd){
              System.out.println(asd.getMessage());
          }
          return v;
      }
  </code></pre>
  
  <p>My servlet:</p>
  
  <pre><code>public class displayservlet extends HttpServlet {
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
        DetailsDao dd = new DetailsDao();
        request.setAttribute("firstname", dd.getStudentFirstName());
          RequestDispatcher view = request.getRequestDispatcher("DemoJSP.jsp");
          view.forward(request, response);
      }
  }
  </code></pre>
  
  <p>My JSP:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
          &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;b&gt;The Demo Object Names Are:-
              &lt;br&gt;
  
              &lt;table&gt;
                  &lt;c:forEach items="${firstname}" var="firstname"&gt;
                      &lt;tr&gt;
                          &lt;td&gt;${firstname}&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/c:forEach&gt;
  
              &lt;/table&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My Display:</p>
  
  <p><img src="https://i.stack.imgur.com/dxJTa.jpg" alt="enter image description here"></p>
  
  <p>Both The first Name and the MiddleName are on the same Column. What is the best way to display a dynamic table using Jstl. an Example would also be Appreciated.</p>
  
  <p>EDIT: My expected Output Is:
  I have added an extra One column:
  <img src="https://i.stack.imgur.com/J2RLK.jpg" alt="enter image description here"></p>