Creating a JSP Page to Handle an Update Action

In this section, you will see how to create the update_action.jsp file. This page processes the form on the edit.jsp page that enables users to update an employee record. There are no visual elements on this page, this page is used only to process the edit.jsp form and returns control to the employees.jsp file.

  1. Create a new JSP page and call it update_action.jsp. Accept all other defaults for the page in the JSP Creation Wizard.
  2. Click and select the Page Directive on the top left corner of the page. The Property Inspector now shows the properties of the Page Directive.
  3. Click the down arrow next to the Import field. The Edit Property: Import dialog box appears. Select the Hierarchy tab and then select ResultSet after extending Java and SQL folders respectively. Click OK.
  4. Add a jsp:usebean tag. Enter empsbean as the ID, and hr.DataHandler as the Class. Set the Scope to session, and click OK.
  5. Add a Scriptlet to the page. Enter the following code into the Insert Scriptlet dialog box:
    Integer employee_id = new Integer(request.getParameter("employee_id"));
    String first_name = request.getParameter("first_name");
    String last_name = request.getParameter("last_name");
    String email = request.getParameter("email");
    String phone_number = request.getParameter("phone_number");
    String salary = request.getParameter("salary");
    String job_id = request.getParameter("job_id");
    empsbean.updateEmployee(employee_id.intValue(), first_name, last_name, email, phone_number, salary, job_id );
    
  6. Add a jsp:forward tag onto the page. In the Insert Forward dialog box, enter employees.jsp for the Page* property.
  7. Save your work.
  8. Run the project and test whether you can edit an employee record. Click Edit for any employee on the employees.jsp page, and you should be directed to the page shown in Figure 5-5. Modify any of the employee details and check whether the change reflects in the employees.jsp page.

Figure 5-5 Editing Employee Data

Description of Figure 5-5 follows
Description of "Figure 5-5 Editing Employee Data"