www.pudn.com > employees.rar > DeleteEmployeeAction.java
package com.wrox;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
public class DeleteEmployeeAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// Default target to success
String target = new String("success");
try {
EmployeeData.removeEmployee(request.getParameter("username"), getDataSource(request));
}
catch ( Exception e ) {
System.err.println("Setting target to error");
target = new String("error");
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("errors.database.error",
e.getMessage()));
// Report any errors
if ( !errors.isEmpty() ) {
saveErrors(request, errors);
}
}
// Forward to the appropriate View
return (mapping.findForward(target));
}
}