Creating a JSP Page to Handle a Delete Action

In the following steps, you create the delete_action.jsp page, which is a page that only processes the delete operation. There are no visual elements on this page.

  1. Create a JSP page and call it delete_action.jsp.
  2. Add a jsp:usebean tag. As before, enter empsbean as the ID, and hr.DataHandler as the Class. Set the Scope to session, and click OK.
  3. Add a Scriptlet to the page. Enter the following code into the Insert Scriptlet dialog box:
    Integer employee_id = 
     new Integer(request.getParameter("empid"));
    empsbean.deleteEmployeeById(employee_id.intValue());
    
  4. Drag Forward from the Component Palette to add a jsp:forward tag to the page. In the Insert Forward dialog box, enter employees.jsp.
  5. Save your work.
  6. Run the project and try deleting an employee. Figure 5-9 shows the links for deleting employee records from the employees.jsp.

    Figure 5-9 Link for Deleting an Employee from employees.jsp

    Description of Figure 5-9 follows
    Description of "Figure 5-9 Link for Deleting an Employee from employees.jsp"

If you click Delete for any of the employee records, then that employee record will be deleted.