Displaying Filtered Data in the JSP Page

In the previous section, you created a text field component on the JSP page that accepts user input. In this text field, users can specify a string with which to filter employee names. You also added a submit button.

In the following steps, you add code to the scriptlet in the employees.java file to enable it to use the getEmployeesByName method. This method is used only if a user submits a value for filtering the results. If this filter criterion is not specified, the getAllEmployees method is used.

  1. Open the employees.jsp file in the Visual Editor.
  2. Double-click the Scriptlet tag on the page (not the one inside the table) to open the Properties dialog box. Modify the code as follows:
    ResultSet rset;
    String query = request.getParameter("query");
    if (query != null)
      rset = empsbean.getEmployeesByName(query);
    else
      rset = empsbean.getAllEmployees();
    

    Figure 4-15 shows how you can use the Scriptlet Properties dialog box to modify the code.

    Figure 4-15 Using the Scriptlet Properties Dialog Box

    Description of Figure 4-15 follows
    Description of "Figure 4-15 Using the Scriptlet Properties Dialog Box"
  3. Click OK.
  4. Save the file.