UserAddAction.java~30~
上传用户: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.             String xm = request.getParameter("xm");
  25.             String sex = request.getParameter("sex");
  26.             String tel = request.getParameter("tel");
  27.             String tel2 = request.getParameter("tel2");
  28.             if (un != null && pwd != null && pwd1 != null && dep != null) {
  29.                 String checksql = "select * from [user] where username = '" +
  30.                                   un +
  31.                                   "' ";
  32.                 String[][] checkun = dbc.getArray(checksql);
  33.                 if (checkun == null) {
  34.                     if (pwd.equals(pwd1)) {
  35.                         String unmd5 = tl.hash(un);
  36.                         String pwdmd5 = tl.hash(pwd);
  37.                         String sql =
  38.                                 "insert into [user] (username,password,deparment,unmd5) values" +
  39.                                 "('" + un + "','" + pwdmd5 + "'," + dep + ",'"+unmd5+"')";
  40.                         dbc.executeUpdate(sql);
  41.                         request.setAttribute("msg",
  42.                                              "用户" + un + "添加成功!密码为" + pwd +
  43.                                              ",所属部门为" + dep + "");
  44.                         return mapping.findForward("succ");
  45.                     } else {
  46.                         request.setAttribute("msg", "再次输入密码不相同,请重新输入!");
  47.                         return mapping.findForward("err");
  48.                     }
  49.                 } else {
  50.                     request.setAttribute("msg", "用户名 " + un + " 已经注册过,请用其他用户名!");
  51.                     return mapping.findForward("err");
  52.                 }
  53.             } else {
  54.                 request.setAttribute("msg", "用户名,密码,部门不允许为空!");
  55.                 return mapping.findForward("err");
  56.             }
  57.         } catch (Exception ex) {
  58.             ex.printStackTrace();
  59.             request.setAttribute("msg", "注册发生异常,请重试!");
  60.         }
  61.         return mapping.findForward("err");
  62.     }
  63. }