PopegroupAddAction.java~38~
上传用户: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 java.io.UnsupportedEncodingException;
  9. import officeol.mc.tools.*;
  10. public class PopegroupAddAction extends Action {
  11.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  12.                                  HttpServletRequest request,
  13.                                  HttpServletResponse response) {
  14.         try {
  15.             request.setCharacterEncoding("GBK");
  16.         } catch (UnsupportedEncodingException ex) {
  17.             ex.printStackTrace();
  18.         }
  19.         try {
  20.             String num = request.getParameter("num");
  21.             String[] ids = new String[Integer.parseInt(num)];
  22.             String pgname = request.getParameter("pgname");
  23.             //System.out.println("pgname "+pgname);
  24.             String[] sql = new String[Integer.parseInt(num)];
  25.             DBConn dbc = new DBConn();
  26.             if (!pgname.equals("")) {
  27.                 String[][] chcek = dbc.getArray(
  28.                         "SELECT * FROM popedomgroup WHERE popegroup='" + pgname +
  29.                         "'");
  30.                 if (chcek != null) {
  31.                     String msg = "用户组" + pgname + "已经存在,请重新输入新的用户组名!";
  32.                     request.setAttribute("msg", msg);
  33.                     return mapping.findForward("err");
  34.                 }
  35.                 for (int i = 0; i < ids.length; i++) {
  36.                     ids[i] = request.getParameter("id" + i);
  37.                     if (ids[i] != null) {
  38.                         sql[i] =
  39.                                 "insert into popedomgroup (popeid,popegroup) values(" +
  40.                                 ids[i] + ",'" + pgname + "')";
  41.                         dbc.executeUpdate(sql[i]);
  42.                     }
  43.                 }
  44.                 System.out.print("添加新用户" + pgname + "组成功!");
  45.                 request.setAttribute("msg", "添加新用户" + pgname + "组成功!");
  46.                 return mapping.findForward("succ");
  47.             } else {
  48.                 request.setAttribute("msg", "paname is null");
  49.                 return mapping.findForward("err");
  50.             }
  51.         } catch (Exception ex) {
  52.             ex.printStackTrace();
  53.         }
  54.         return mapping.findForward("err");
  55.     }
  56. }