Home >Web Front-end >JS Tutorial >The jsp page displays the data information table of the database

The jsp page displays the data information table of the database

高洛峰
高洛峰Original
2017-01-10 11:32:482934browse

In daily jsp development; one of the most basic operations is to display the information previously added to the database in the jsp page, which is part of the search in the add, delete, modify, and query;

Below It is the development steps and analysis of the above part.

1. In jsp page:

<thead>
<tr>
<th>用户名称</th>
<th>用户性别</th>
<th>用户年龄</th>
</tr>
</thead>
<tbody>
<% AccountDAO accountdao=new AccountDAO(); List list=accountdao.select();//从数据库中查询所有的用户,得到的是一个集合(数组)
 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")?"男":"女")+"");
 out.write(""+account.getAge()+"");
 out.write("");
}
%>
</tbody>

2. In html page:

<thead>
<tr>
<th>用户名称</th>
<th>用户性别</th>
<th>用户年龄</th>
</tr>
</thead>
<tbody>
<tr>
<td>王五</td>
<td>男</td>
<td>20</td>
</tr>
<tr>
<td>里斯</td>
<td>男</td>
<td>22</td>
</tr>
</tbody>

jsp page and html page:

The jsp page displays the data information table of the database

Data in the database:

The jsp page displays the data information table of the database

Both are displayed The effect is the same, except that one is a dynamic web page and the other is a static web page.

Part two 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">查看</a> <a href="#" class="tablelink"> 删除</a></td>
</tr>
<%
 }
%>

The above is the entire content of this article. I hope that the content of this article can bring some help to everyone's study or work. I also hope to support the PHP Chinese website!

For more articles related to the jsp page displaying the data information table of the database, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn