UserAddAction.java~28~
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:3k
源码类别:

OA系统

开发平台:

Java

  1. package officeol.mc.actions;
  2. import org.apache.struts.action.ActionMapping;
  3. import org.apache.struts.action.ActionForm;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.Action;
  8. import officeol.mc.tools.*;
  9. public class UserAddAction extends Action {
  10.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  11.                                  HttpServletRequest request,
  12.                                  HttpServletResponse response) {
  13.         try {
  14.             request.setCharacterEncoding("GBK");
  15.             DBConn dbc = new DBConn();
  16.             Tool tl = new Tool();
  17.             String un = StringFilter.filter(tl.isNull(request.getParameter(
  18.                     "username").trim()));
  19.             String pwd = StringFilter.filter(tl.isNull(request.getParameter(
  20.                     "pwd").trim()));
  21.             String pwd1 = StringFilter.filter(tl.isNull(request.getParameter(
  22.                     "pwd2").trim()));
  23.             String dep = "0";
  24.             if (un != null && pwd != null && pwd1 != null && dep != null) {
  25.                 String checksql = "select * from [user] where username = '" +
  26.                                   un +
  27.                                   "' ";
  28.                 String[][] checkun = dbc.getArray(checksql);
  29.                 if (checkun == null) {
  30.                     if (pwd.equals(pwd1)) {
  31.                         String unmd5 = tl.hash(un);
  32.                         String pwdmd5 = tl.hash(pwd);
  33.                         String sql =
  34.                                 "insert into [user] (username,password,deparment,unmd5) values" +
  35.                                 "('" + un + "','" + pwdmd5 + "'," + dep + ",'"+unmd5+"')";
  36.                         dbc.executeUpdate(sql);
  37.                         request.setAttribute("msg",
  38.                                              "用户" + un + "添加成功!密码为" + pwd +
  39.                                              ",所属部门为" + dep + "");
  40.                         return mapping.findForward("succ");
  41.                     } else {
  42.                         request.setAttribute("msg", "再次输入密码不相同,请重新输入!");
  43.                         return mapping.findForward("err");
  44.                     }
  45.                 } else {
  46.                     request.setAttribute("msg", "用户名 " + un + " 已经注册过,请用其他用户名!");
  47.                     return mapping.findForward("err");
  48.                 }
  49.             } else {
  50.                 request.setAttribute("msg", "用户名,密码,部门不允许为空!");
  51.                 return mapping.findForward("err");
  52.             }
  53.         } catch (Exception ex) {
  54.             ex.printStackTrace();
  55.             request.setAttribute("msg", "注册发生异常,请重试!");
  56.         }
  57.         return mapping.findForward("err");
  58.     }
  59. }