The jsp page displays the database data information table and jsp information table.

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.