EmpQueryAction.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.ActionMessage;
  9. import org.apache.struts.action.ActionMessages;
  10. import javax.servlet.ServletContext;
  11. import javax.sql.DataSource;
  12. import java.sql.Connection;
  13. import javax.servlet.http.*;
  14. import java.util.*;
  15. import org.apache.struts.action.DynaActionForm;
  16. public final class EmpQueryAction extends Action{  
  17. public ActionForward execute(
  18. ActionMapping mapping,
  19. ActionForm form,
  20. HttpServletRequest request,  
  21. HttpServletResponse response) throws Exception {
  22. DynaActionForm empQueryForm = (DynaActionForm) form;         
  23. Integer depId = (Integer)empQueryForm.get("depId");
  24. String name = (String)empQueryForm.get("name");
  25.     ServletContext context = servlet.getServletContext();
  26. DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
  27.         DB db = new DB(dataSource);
  28.         HttpSession session = request.getSession(true);
  29. Vector empList = new Vector();
  30. String PageForward;
  31. ActionMessages errors = new ActionMessages();
  32.     String username=(String)session.getAttribute(Constants.LOGIN_USERNAME_KEY);
  33.        
  34. if (username==null){
  35.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  36.                            new ActionMessage("errors.accessDeny"));
  37. if (!errors.isEmpty()) {
  38. saveErrors(request, errors);
  39.   PageForward="toWrong";  
  40. }
  41.         else {
  42. session.setAttribute(Constants.EMP_LIST_KEY,Emp.Search(db,depId.intValue(),name));
  43.    PageForward="toEmpQueryResult";  
  44.         }
  45.       
  46. db.close();
  47.      return  mapping.findForward(PageForward);  
  48. }
  49. }