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

Java编程

开发平台:

Java

  1. package StudyBbs;
  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 java.util.*;
  14. import javax.servlet.http.*;
  15. public final class ActionUserAdmin extends Action{  
  16. public ActionForward execute(
  17. ActionMapping mapping,
  18. ActionForm form,
  19. HttpServletRequest request,  
  20. HttpServletResponse response) throws Exception {
  21.         HttpSession session = request.getSession();
  22. Vector users = new Vector();
  23.     ServletContext context = servlet.getServletContext();
  24. DataSource dataSource = 
  25. (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
  26. DB db = new DB(dataSource);
  27.         String usergrade=(String)session.getAttribute(Constants.LOGIN_USERGRADE_KEY);
  28.         
  29. String PageForward;
  30. ActionMessages errors = new ActionMessages();
  31. if ("管理员".equals(usergrade)){
  32. users = User.Search(db,"");
  33. session.setAttribute(Constants.USER_LIST_KEY,users);
  34.   PageForward="toUserAdmin";  
  35. }
  36.         else {
  37.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  38.                            new ActionMessage("errors.accessDeny"));
  39. if (!errors.isEmpty()) {
  40. saveErrors(request, errors);
  41.   PageForward="toWrong";  
  42.         }
  43.    
  44. db.close();
  45.     return (mapping.findForward(PageForward));
  46.   }
  47. }