The jsp page displays the database data information table and jsp information table.
In daily jsp development, one of the most basic operations is to display the information previously added to the database on the jsp page, which is part of the Search In addition, deletion, modification, and query;
The following are the development steps and Analysis of the above section.
1. On the jsp page:
<Thead>
<Tr>
<Th> User Name </th>
<Th> User gender </th>
<Th> User age </th>
</Tr>
</Thead>
<Tbody>
<% AccountDAO accountdao = new AccountDAO (); List list = accountdao. select (); // query all users from the database and obtain a set (array)
For (int I = 0; I <list. size (); I ++) {Account account = list. get (I); out. write (""); out. write ("" + account. getAname () + "");
Out. write ("" + (account. getSex (). equals ("m ")? "Male": "female") + "");
Out. write ("" + account. getAge () + "");
Out. write ("");
}
%>
</Tbody>
2. On the html page:
<Thead>
<Tr>
<Th> User Name </th>
<Th> User gender </th>
<Th> User age </th>
</Tr>
</Thead>
<Tbody>
<Tr>
<Td> Wang Wu </td>
<Td> male </td>
<Td> 20 </td>
</Tr>
<Tr>
<Td> RIS </td>
<Td> male </td>
<Td> 22 </td>
</Tr>
</Tbody>
Jsp page and html page:
Data in the database:
The two show the same effect, but one is a dynamic webpage and the other is a static webpage.
Part II code:
TeacherDao teacherDao = new TeacherDao ();
List <Teacher> teachers = teacherDao. findAllTeacher ();
For (int I = 0; I <teachers. size (); I ++ ){
Teacher teacher = teachers. get (I );
%>
<Tr>
<Td> <input name = "" type = "checkbox" value = ""/> </td>
<Td> <% = teacher. getTno () %> </td>
<Td> <% = teacher. getTname () %> </td>
<Td> <% = teacher. getTsex () %> </td>
<Td> <% = teacher. getProf () %> </td>
<Td> <% = teacher. getDepart () %> </td>
<Td> <% = teacher. getTbirthday () %> </td>
<Td> <a href = "#" class = "tablelink"> View </a> <a href = "#" class = "tablelink"> Delete </a> </td>
</Tr>
<%
}
%>
Conclusion: Learn with your heart and pay attention to the summary!