Dynamic database table display using Jstl [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 02:43:51
newuser

Try this,

create a new Bean class named as Name

public class Name
{
    private String firstName;
    private String middleName;
    private String lastName;

   // relavent getter setter
}

change your method getStudentFirstName()

public ArrayList getStudentFirstName(){
        ArrayList<Name> v = new ArrayList<Name>();
        Connection conn;
        try{
         conn =  db.getDbConnection();
         String sql = "select STU_FIRST_NAME, STU_MIDDLE_NAME from college_students_master";
         PreparedStatement ps = conn.prepareStatement(sql);
         ResultSet rs = ps.executeQuery();
         Name name = null;
         while(rs.next()){
             name = new Name();
             name.setFirstName(rs.getString("STU_FIRST_NAME")); //set your firstName
             name.setMiddleName(rs.getString("STU_MIDDLE_NAME")); //set your MiddleName
             name.setLastName(rs.getString("LAST_NAME")); //set your LastName
             v.add(name); 
         }
        }catch(Exception asd){
            System.out.println(asd.getMessage());
        }
        return v;
    }

change your c:forEach Loop

<table border="1">
  <thead>
    <td>
      <th>First Name</th>
      <th>Middle Name</th>
      <th>Last Name</th>
    </td>
  </thead>
  <tbody>
     <c:forEach items="${firstname}" var="name">
       <tr>
         <td>${name.firstName}</td>
         <td>${name.middleName}</td>
         <td>${name.lastName}</td>
       </tr>
     </c:forEach>
  </tbody>
</table>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!