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

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 DeparAddAction extends Action {
  10.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  11.                                  HttpServletRequest request,
  12.                                  HttpServletResponse response) {
  13.         try{
  14.             request.setCharacterEncoding("GBK");
  15.             Tool tl = new Tool();
  16.             DBConn dbc = new DBConn();
  17.             String dn = request.getParameter("dpname");
  18.             String dsm = request.getParameter("dpsm");
  19.             String dnmd5 = tl.hash(dn);
  20.             String dnsql = "select count(*) from deparment where deparname ='"+dn+"' ";
  21.             String[][] dncheck = dbc.getArray(dnsql);
  22.             if(dncheck[0][0].equals("0")){
  23.                 String dsql =
  24.                         "insert into deparment (deparname,shuoming,dnmd5) values('" +
  25.                         dn + "','" + dsm + "','" + dnmd5 + "')";
  26.                 dbc.executeUpdate(dsql);
  27.                 request.setAttribute("msg", "添加用户部门 " + dn + " 成功!");
  28.                 return mapping.findForward("succ");
  29.             }else{
  30.                 request.setAttribute("msg", "添加用户部门 " + dn + " 失败! 部门名"+dn +"已经存在!");
  31.             }
  32.         }catch(Exception ex){
  33.             ex.printStackTrace();
  34.         }
  35.         return mapping.findForward("err");
  36.     }
  37. }