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