Adding a Table to the JSP Page to Display the Result Set

The following steps describe how you can add a table to the JSP page to display the results of the getAllEmployees query:

  1. If the employees.jsp page is not open in the Visual Editor, double-click it in the Application Navigator to open it, and work in the Design tab. With the employees.jsp file open in the Visual Editor, position the cursor after the scriptlet and from the HTML Common page of the Component Palette, select the Table component, which is shown in Figure 4-12.

    Figure 4-12 Common HTML Components in the Component Palette

    Description of Figure 4-12 follows
    Description of "Figure 4-12 Common HTML Components in the Component Palette"
  2. In the Insert Table dialog box, specify 1 row and 6 columns. Leave all Layout properties as default. Click OK.
  3. In the table row displayed on the page, enter text as follows for the headings for each of the columns: First Name, Last Name, Email, Job, Phone, Salary. Use Heading 4 to format the column names.
  4. Add a scripting element for output, this time to display the values returned for each of the columns in the table. To do this, select the table as follows. Position the cursor on the top border of the table, and click when the cursor image changes to a table image. From the JSP Component Palette, select Scriptlet. (You need not drag the scriptlet into your table; it is inserted automatically.)
  5. In the Insert Scriptlet dialog box, enter the following lines of code:
        while (rset.next ())
        {
        out.println("<tr>");
        out.println("<td>" + 
          rset.getString("first_name") + "</td><td> " + 
          rset.getString("last_name") + "</td><td> " + 
          rset.getString("email") + "</td><td> " + 
          rset.getString("job_id") + "</td><td>" + 
          rset.getString("phone_number") + "</td><td>" + 
          rset.getDouble("salary") + "</td>");
        out.println("</tr>");
        }
    
  6. Click OK.

The JSP page created is shown in Figure 4-13.

Figure 4-13 Table in a JSP Page

Description of Figure 4-13 follows
Description of "Figure 4-13 Table in a JSP Page"