ActionUserEdit.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 javax.servlet.ServletContext;
  9. import javax.sql.DataSource;
  10. import java.sql.Connection;
  11. import java.sql.Statement;
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.util.*;
  15. import javax.servlet.http.*;
  16. import org.apache.struts.action.DynaActionForm;
  17. import org.apache.struts.action.ActionMessage;
  18. import org.apache.struts.action.ActionMessages;
  19. public final class ActionUserEdit extends Action{  
  20. public ActionForward execute(
  21. ActionMapping mapping,
  22. ActionForm form,
  23. HttpServletRequest request,  
  24. HttpServletResponse response) throws Exception {
  25.     DynaActionForm userAdminform = (DynaActionForm) form;         
  26. String username = (String)userAdminform.get("username");
  27. String gradeId = (String)userAdminform.get("grade");
  28. String sort = (String)userAdminform.get("sort");
  29.         String grade = null;
  30.         if (gradeId.equals("0")) {
  31.          grade = "管理员";
  32.         }
  33.         else if (gradeId.equals("1")) {
  34.          grade = "斑竹";
  35.         }
  36.         else if (gradeId.equals("2")){
  37.          grade = "普通用户";
  38.          }
  39.         
  40.         HttpSession session = request.getSession();
  41. Vector users = new Vector();
  42.     ServletContext context = servlet.getServletContext();
  43. DataSource dataSource = 
  44. (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
  45.         DB db = new DB(dataSource);
  46.         
  47. String PageForward;
  48. ActionMessages errors = new ActionMessages();
  49. if (User.Edit(db,username,grade,sort)){
  50. users = User.Search(db,"");
  51. session.setAttribute(Constants.USER_LIST_KEY,users);
  52. PageForward="toUserAdmin";
  53. }
  54. else{
  55.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  56.                            new ActionMessage("errors.updateFail"));
  57. if (!errors.isEmpty()) {
  58. saveErrors(request, errors);
  59.   PageForward="toWrong";  
  60. }
  61.    
  62. db.close();
  63.     return (mapping.findForward(PageForward));
  64.   }
  65. }