jsp頁面顯示資料庫的資料資訊表,jsp資訊表

來源:互聯網
上載者:User

jsp頁面顯示資料庫的資料資訊表,jsp資訊表

 

   在日常jsp開發中;最基本的一個操作之一是把之前添加到資料庫中的資訊在jsp頁面中顯示出來,也就是增刪改查中的尋找的一部分;

下面是以上部分的開發步驟及分析。

  1.在jsp頁面:

<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.在html頁面:

<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頁面和html頁面:

             

資料庫中的資料:

                             

      兩者顯示效果相同只不過一個是動態網頁一個是靜態網頁罷了。

二 部分代碼:

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>
<%
      }
%>

總結:用心學習,注意總結,就好了!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.