EmpDelAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. package StudyNote;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import org.apache.struts.action.Action;
  5. import org.apache.struts.action.ActionForm;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.ActionMapping;
  8. import org.apache.struts.action.DynaActionForm;
  9. import org.apache.struts.action.ActionMessage;
  10. import org.apache.struts.action.ActionMessages;
  11. import javax.servlet.ServletContext;
  12. import javax.sql.DataSource;
  13. import java.sql.Connection;
  14. import java.sql.Statement;
  15. import java.sql.ResultSet;
  16. import java.sql.SQLException;
  17. import java.util.*;
  18. import javax.servlet.http.*;
  19. public final class EmpDelAction extends Action{  
  20. public ActionForward execute(
  21. ActionMapping mapping,
  22. ActionForm form,
  23. HttpServletRequest request,  
  24. HttpServletResponse response) throws Exception {
  25.     DynaActionForm empIdForm = (DynaActionForm) form;         
  26. Integer empId = (Integer)empIdForm.get("empId");
  27.         HttpSession session = request.getSession();
  28. Vector empList = new Vector();
  29.     ServletContext context = servlet.getServletContext();
  30. DataSource dataSource = 
  31. (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
  32.         DB db = new DB(dataSource);
  33.         
  34. String PageForward;
  35. ActionMessages errors = new ActionMessages();
  36. if (Emp.Delete(db,empId.intValue())){
  37. session.setAttribute(Constants.EMP_LIST_KEY,Emp.Search(db,0,""));
  38. PageForward="empPreDel";
  39. }
  40. else{
  41.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  42.                            new ActionMessage("errors.deleteFail"));
  43. if (!errors.isEmpty()) {
  44. saveErrors(request, errors);
  45.   PageForward="toWrong";  
  46. }
  47. db.close();
  48.     return (mapping.findForward(PageForward));
  49.   }
  50. }