Example #1
0
  // 后台添加管理员   上传头像
  public void insert(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      // 1实例化SmartUpload对象
      SmartUpload su = new SmartUpload();
      // 2 初始化
      su.initialize(this.getServletConfig(), request, response);
      // 3 上传
      su.upload();
      // 4 原名保存所有文件
      su.save("/uploadImage");

      Request req = su.getRequest();
      String name = req.getParameter("name");
      String password = req.getParameter("password");
      String access = req.getParameter("access");
      String pic = req.getParameter("pic");
      int n = pic.lastIndexOf("\\");
      String p = pic.substring(n + 1, pic.length());
      Manager manager = new Manager();
      manager.setName(name);
      manager.setPassword(password);
      manager.setPic(p);
      manager.setAccess(access);
      ManagerDAO.getDAO().insertManager(manager);
      response.sendRedirect("http://localhost:8080/supermarket/manage/jsp/index.jsp");

    } catch (SmartUploadException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    SmartUpload mySmartUpload = new SmartUpload();
    mySmartUpload.initialize(config, request, response);
    mySmartUpload.setMaxFileSize(40000 * 20000);
    mySmartUpload.setAllowedFilesList("gif,jpg,bmp,JPG,png"); // "jpg,gif,png,jpeg,bmp"
    try {
      mySmartUpload.upload();
      File myFile = mySmartUpload.getFiles().getFile(0);
      if (!myFile.isMissing()) {

        Date currTime = new Date();
        SimpleDateFormat formatter2 = new SimpleDateFormat("yyyyMMddhhmmssS", Locale.US);
        FileName = new String((formatter2.format(currTime)).getBytes("iso-8859-1"));
        String ext = myFile.getFileExt();
        FileName = FileName + "." + ext;

        myFile.saveAs(sPath + "/" + FileName, mySmartUpload.SAVE_VIRTUAL);
      }
      response.sendRedirect("/MacaoeasyBuy/uploadimage.jsp?Picurl=" + FileName + "&step=2");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #3
0
  private ActionForward impScore(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    try {
      request.setCharacterEncoding("utf-8");
      response.setCharacterEncoding("utf-8");
      String path = request.getContextPath();
      String rootPath = request.getSession().getServletContext().getRealPath("/");
      // 先建文件夹
      String folderPath = rootPath + "export/";
      String str_Path = folderPath.toString().replace("\\", "/");
      // 上传文件
      SmartUpload mySmartUpload = new SmartUpload();
      // 设置允许上传的文件类型
      // mySmartUpload.setAllowedFilesList("xls");
      ServletConfig config = this.getServlet().getServletConfig();
      mySmartUpload.initialize(config, request, response);
      mySmartUpload.upload();

      String CURDATE = GetRecentDate.getRecentDate("yyyyMMddHHmmssS");
      String FILE_PATH = "";
      for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
        com.jspsmart.upload.File file = mySmartUpload.getFiles().getFile(i);
        if (!file.getFileName().equals("")) {
          FILE_PATH = str_Path + CURDATE + "_" + i + "." + file.getFileExt();
          file.saveAs(FILE_PATH);
        }
      }

      ScoreManagementDAO dao = new ScoreManagementDAO();
      InputStream stream = new FileInputStream(FILE_PATH);
      Workbook rwb = Workbook.getWorkbook(stream);
      Sheet sheet = rwb.getSheet(0);
      for (int i = 1; i < sheet.getRows(); i++) {
        String SCORE_YEAR = sheet.getCell(0, i).getContents(); // 年份
        if (SCORE_YEAR.equals("")) break;
        String SEMESTER = sheet.getCell(1, i).getContents(); // 学期
        String SCORE_GRADE = sheet.getCell(2, i).getContents(); // 班级
        String SCORE_CLASS = sheet.getCell(3, i).getContents(); // 班级
        String SCORE_NO = sheet.getCell(4, i).getContents(); // 学号
        String STU_NAME = sheet.getCell(5, i).getContents(); // 姓名
        String STU_SEX = sheet.getCell(6, i).getContents(); // 性别
        String AAS = sheet.getCell(7, i).getContents(); // 文理科
        String KEMU = sheet.getCell(8, i).getContents(); // 考试名称
        String CHINESE = sheet.getCell(9, i).getContents(); // 语文
        if (CHINESE.equals("")) CHINESE = "0";
        String MATCH = sheet.getCell(10, i).getContents(); // 数学
        if (MATCH.equals("")) MATCH = "0";
        String ENGLISH = sheet.getCell(12, i).getContents(); // 英语
        if (ENGLISH.equals("")) ENGLISH = "0";
        String PHYSICAL = sheet.getCell(13, i).getContents(); // 物理
        if (PHYSICAL.equals("")) PHYSICAL = "0";
        String CHEMISTRY = sheet.getCell(14, i).getContents(); // 化学
        if (CHEMISTRY.equals("")) CHEMISTRY = "0";
        String BIOLOGICAL = sheet.getCell(15, i).getContents(); // 生物
        if (BIOLOGICAL.equals("")) BIOLOGICAL = "0";
        String HISTORY = sheet.getCell(16, i).getContents(); // 历史
        if (HISTORY.equals("")) HISTORY = "0";
        String POLITY = sheet.getCell(17, i).getContents(); // 政治
        if (POLITY.equals("")) POLITY = "0";
        String GEOGRAPHY = sheet.getCell(18, i).getContents(); // 地理
        if (GEOGRAPHY.equals("")) GEOGRAPHY = "0";
        float total =
            Float.valueOf(CHINESE)
                + Float.valueOf(MATCH)
                + Float.valueOf(ENGLISH)
                + Float.valueOf(PHYSICAL)
                + Float.valueOf(CHEMISTRY)
                + Float.valueOf(BIOLOGICAL)
                + Float.valueOf(HISTORY)
                + Float.valueOf(POLITY)
                + Float.valueOf(GEOGRAPHY);

        HashMap map = new HashMap();
        map.put("SCORE_YEAR", SCORE_YEAR);
        map.put("SEMESTER", SEMESTER);
        map.put("SCORE_GRADE", SCORE_GRADE);
        map.put("SCORE_CLASS", SCORE_CLASS);
        map.put("SCORE_NO", SCORE_NO);
        map.put("STU_NAME", STU_NAME);
        map.put("STU_SEX", STU_SEX);
        map.put("AAS", AAS);
        map.put("KEMU", KEMU);
        map.put("CHINESE", CHINESE);
        map.put("MATCH", MATCH);
        map.put("ENGLISH", ENGLISH);
        map.put("PHYSICAL", PHYSICAL);
        map.put("CHEMISTRY", CHEMISTRY);
        map.put("BIOLOGICAL", BIOLOGICAL);
        map.put("HISTORY", HISTORY);
        map.put("POLITY", POLITY);
        map.put("GEOGRAPHY", GEOGRAPHY);
        map.put("TOTAL_SCORE", total);
        dao.insertScore(map);
      }
      rwb.close();
      stream.close();
      response.getWriter().write("1");
      response.getWriter().close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
  public synchronized void service(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    HttpSession dbSession = request.getSession();
    JspFactory _jspxFactory = JspFactory.getDefaultFactory();
    PageContext pageContext =
        _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
    ServletContext dbApplication = dbSession.getServletContext();

    try {
      // 实例化

      HttpSession session = request.getSession();
      ServletContext context = session.getServletContext();
      String path = context.getRealPath("/");
      counter count = new counter(dbApplication);
      SmartUpload mySmartUpload = new SmartUpload();
      mySmartUpload.setCharset("UTF-8");
      nseer_db_backup1 qcs_db = new nseer_db_backup1(dbApplication);

      if (qcs_db.conn((String) dbSession.getAttribute("unit_db_name"))) {

        mySmartUpload.initialize(pageContext);
        String file_type = getFileLength.getFileType((String) session.getAttribute("unit_db_name"));
        long d = getFileLength.getFileLength((String) session.getAttribute("unit_db_name"));
        mySmartUpload.setMaxFileSize(d);
        mySmartUpload.setAllowedFilesList(file_type);

        try {
          mySmartUpload.upload();
          String qcs_id = mySmartUpload.getRequest().getParameter("qcs_id");
          String config_id = mySmartUpload.getRequest().getParameter("config_id");

          String[] item = mySmartUpload.getRequest().getParameterValues("item");
          if (item != null) {
            String[] file_name = new String[mySmartUpload.getFiles().getCount()];
            String[] not_change = new String[mySmartUpload.getFiles().getCount()];
            java.util.Date now = new java.util.Date();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
            String time = formatter.format(now);
            String standard_id = mySmartUpload.getRequest().getParameter("standard_id");
            String sqla =
                "select attachment1 from qcs_intrmanufacture where qcs_id='"
                    + qcs_id
                    + "' and (check_tag='5' or check_tag='9')";
            ResultSet rs = qcs_db.executeQuery(sqla);
            if (!rs.next()) {
              response.sendRedirect("draft/qcs/intrmanufacture_ok.jsp?finished_tag=1");
            } else {
              String[] attachment = mySmartUpload.getRequest().getParameterValues("attachment");
              String[] delete_file_name = new String[0];
              if (attachment != null) {
                delete_file_name = new String[attachment.length];
                for (int i = 0; i < attachment.length; i++) {
                  delete_file_name[i] = rs.getString(attachment[i]);
                }
              }
              for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
                com.jspsmart.upload.SmartFile file = mySmartUpload.getFiles().getFile(i);
                if (file.isMissing()) {
                  file_name[i] = "";
                  int q = i + 1;
                  String field_name = "attachment" + q;
                  if (!rs.getString(field_name).equals("")) not_change[i] = "yes";
                  continue;
                }
                int filenum =
                    count.read(
                        (String) dbSession.getAttribute("unit_db_name"), "qcsAttachmentcount");
                count.write(
                    (String) dbSession.getAttribute("unit_db_name"), "qcsAttachmentcount", filenum);
                file_name[i] = filenum + file.getFileName();
                file.saveAs(path + "qcs/file_attachments/" + filenum + file.getFileName());
              }
              String apply_id = mySmartUpload.getRequest().getParameter("apply_id");
              String product_id = mySmartUpload.getRequest().getParameter("product_id");
              String product_name = mySmartUpload.getRequest().getParameter("product_name");
              String qcs_amount = mySmartUpload.getRequest().getParameter("qcs_amount");
              String qcs_time = mySmartUpload.getRequest().getParameter("qcs_time");
              String quality_way = mySmartUpload.getRequest().getParameter("quality_way");
              String quality_solution = mySmartUpload.getRequest().getParameter("quality_solution");
              String sampling_standard =
                  mySmartUpload.getRequest().getParameter("sampling_standard");
              String sampling_amount = mySmartUpload.getRequest().getParameter("sampling_amount");
              String accept = mySmartUpload.getRequest().getParameter("accept");
              String reject = mySmartUpload.getRequest().getParameter("reject");
              String qualified = mySmartUpload.getRequest().getParameter("qualified");
              String unqualified = mySmartUpload.getRequest().getParameter("unqualified");
              String qcs_result = mySmartUpload.getRequest().getParameter("qcs_result");
              String checker = mySmartUpload.getRequest().getParameter("checker");
              String checker_id = mySmartUpload.getRequest().getParameter("checker_id");
              String check_time = mySmartUpload.getRequest().getParameter("check_time");
              String changer = mySmartUpload.getRequest().getParameter("changer");
              String changer_id = mySmartUpload.getRequest().getParameter("changer_id");
              String change_time = mySmartUpload.getRequest().getParameter("change_time");
              String bodyab =
                  new String(
                      mySmartUpload.getRequest().getParameter("remark").getBytes("UTF-8"), "UTF-8");
              String remark = exchange.toHtml(bodyab);

              sqla =
                  "update qcs_intrmanufacture set apply_id='"
                      + apply_id
                      + "',product_id='"
                      + product_id
                      + "',product_name='"
                      + product_name
                      + "',qcs_amount='"
                      + qcs_amount
                      + "',qcs_time='"
                      + qcs_time
                      + "',quality_way='"
                      + quality_way
                      + "',quality_solution='"
                      + quality_solution
                      + "',sampling_standard='"
                      + sampling_standard
                      + "',sampling_amount='"
                      + sampling_amount
                      + "',accept='"
                      + accept
                      + "',reject='"
                      + reject
                      + "',qualified='"
                      + qualified
                      + "',unqualified='"
                      + unqualified
                      + "',changer_id='"
                      + changer_id
                      + "',qcs_result='"
                      + qcs_result
                      + "',changer='"
                      + changer
                      + "',change_time='"
                      + change_time
                      + "',remark='"
                      + remark
                      + "',check_tag='5'";
              String sqlb = " where qcs_id='" + qcs_id + "'";
              if (attachment != null) {
                for (int i = 0; i < attachment.length; i++) {
                  sqla = sqla + "," + attachment[i] + "=''";
                  java.io.File file =
                      new java.io.File(path + "qcs/file_attachments/" + delete_file_name[i]);
                  file.delete();
                }
              }
              for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
                if (not_change[i] != null && not_change[i].equals("yes")) continue;
                int p = i + 1;
                sqla = sqla + ",attachment" + p + "='" + file_name[i] + "'";
              }
              String sql = sqla + sqlb;
              qcs_db.executeUpdate(sql);

              sql = "delete from qcs_intrmanufacture_details where qcs_id='" + qcs_id + "'";
              qcs_db.executeUpdate(sql);

              String[] default_basis =
                  mySmartUpload.getRequest().getParameterValues("default_basis");
              String[] ready_basis = mySmartUpload.getRequest().getParameterValues("ready_basis");
              String[] quality_method =
                  mySmartUpload.getRequest().getParameterValues("quality_method");
              String[] analyse_method =
                  mySmartUpload.getRequest().getParameterValues("analyse_method");
              String[] standard_value =
                  mySmartUpload.getRequest().getParameterValues("standard_value");
              String[] standard_max = mySmartUpload.getRequest().getParameterValues("standard_max");
              String[] standard_min = mySmartUpload.getRequest().getParameterValues("standard_min");
              String[] quality_value =
                  mySmartUpload.getRequest().getParameterValues("quality_value");
              String[] sampling_amount_d =
                  mySmartUpload.getRequest().getParameterValues("sampling_amount_d");
              String[] qualified_d = mySmartUpload.getRequest().getParameterValues("qualified_d");
              String[] unqualified_d =
                  mySmartUpload.getRequest().getParameterValues("unqualified_d");
              String[] quality_result =
                  mySmartUpload.getRequest().getParameterValues("quality_result");
              String[] unqualified_reason =
                  mySmartUpload.getRequest().getParameterValues("unqualified_reason");
              for (int i = 0; i < item.length; i++) {
                if (!item[i].equals("")) {
                  sql =
                      "insert into qcs_intrmanufacture_details(qcs_id,item,default_basis,ready_basis,quality_method,analyse_method,standard_value,standard_max,standard_min,quality_value,sampling_amount_d,qualified_d,unqualified_d,quality_result,unqualified_reason,details_number) values('"
                          + qcs_id
                          + "','"
                          + item[i]
                          + "','"
                          + default_basis[i]
                          + "','"
                          + ready_basis[i]
                          + "','"
                          + quality_method[i]
                          + "','"
                          + analyse_method[i]
                          + "','"
                          + standard_value[i]
                          + "','"
                          + standard_max[i]
                          + "','"
                          + standard_min[i]
                          + "','"
                          + quality_value[i]
                          + "','"
                          + sampling_amount_d[i]
                          + "','"
                          + qualified_d[i]
                          + "','"
                          + unqualified_d[i]
                          + "','"
                          + quality_result[i]
                          + "','"
                          + unqualified_reason[i]
                          + "','"
                          + i
                          + "')";
                  qcs_db.executeUpdate(sql);
                }
              }
              response.sendRedirect("draft/qcs/intrmanufacture_ok.jsp?finished_tag=0");
            }
            qcs_db.commit();
            qcs_db.close();
          } else {
            response.sendRedirect("draft/qcs/intrmanufacture_ok.jsp?finished_tag=7");
          }

        } catch (Exception ex) {
          response.sendRedirect("draft/qcs/intrmanufacture_ok.jsp?finished_tag=6");
        }

      } else {
        response.sendRedirect("error_conn.htm");
      }

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Example #5
0
  // 添加新闻(实现文件上传)
  public void newsAdd(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String filename = "";

    SmartUpload su = new SmartUpload();
    // 初始化SmartUpload对象
    su.initialize(this.getServletConfig(), request, response);
    com.jspsmart.upload.File file = null;
    // 允许上传类型
    String allowed = "gif,jpg,doc,rar";
    // 不许上传类型
    String denied = "jsp,asp,php,aspx,html,htm,exe,bat";
    com.jspsmart.upload.Request req = null;
    // 设置上传文件大小
    int file_size = 10 * 1024 * 1024; // 10mb
    String exceptionMsg = null;
    int i = 0;
    try {
      // 定义允许上传文件类型
      su.setAllowedFilesList(allowed);
      // 不允许上传文件类型
      su.setDeniedFilesList(denied);
      // 单个文件最大限制
      su.setMaxFileSize(file_size);
      su.setCharset("GBK");
      // 执行上传
      su.upload();
      // 得到单个上传文件的信息
      file = su.getFiles().getFile(0);
      String filepath = null;
      if (!file.isMissing()) {
        // 设置文件在服务器的保存位置

        filepath = "upload\\";
        filename = file.getFileName();
        String ext = filename.substring(filename.lastIndexOf(".") + 1);
        Date date = new Date();
        filename = date.getTime() + "" + (int) (Math.random() * 100000) + "." + ext;
        filepath += filename;
        // 文件另存为
        file.setCharset("gbk");
        file.saveAs(filepath, SmartUpload.SAVE_VIRTUAL);
      }

      // 获取smartupload封装的request
      req = su.getRequest();
      // 获取添加新闻页面传递过来的参数
      int typeId = Integer.parseInt(req.getParameter("typeId"));
      String title = req.getParameter("title");
      String author = req.getParameter("author");
      String summary = req.getParameter("summary");
      String content = req.getParameter("content");
      String pic = filepath; // 获取文件上传后的路径

      NewsInfo newsInfo = new NewsInfo();
      newsInfo.setTypeId(typeId);
      newsInfo.setNewsTitle(title);
      newsInfo.setNewsAut(author);
      newsInfo.setNewsSum(summary);
      newsInfo.setNewsCon(content);
      newsInfo.setNewsPic(pic);
      newsInfo.setNewsDate(new Date());

      boolean flag = newsDao.addNewsInfo(newsInfo);
      if (flag) {
        newsList(request, response);
      } else {
        request.setAttribute("error", "添加新闻失败!");

        request.setAttribute("newsInfo", newsInfo);

        gotoNewsAdd(request, response);
      }
    } catch (Exception e) {
      exceptionMsg = e.getMessage();
      e.printStackTrace();
      request.setAttribute("error", "添加新闻失败!");
      gotoNewsAdd(request, response);
    }
  }
Example #6
0
  /**
   * The doPost method of the servlet. <br>
   * This method is called when a form has its tag value method equals to post.
   *
   * @param request the request send by the client to the server
   * @param response the response send by the server to the client
   * @throws ServletException if an error occurred
   * @throws IOException if an error occurred
   */
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    response.setContentType("text/html;charset=utf-8");
    PrintWriter out = response.getWriter();
    String id = "";
    WorksInfoLogic worksInfoLogic = new WorksInfoLogic();
    if (request.getParameter("action") != null) {
      id = request.getParameter("works_id");
      // System.out.println("id:::"+id);
      boolean flag = worksInfoLogic.delWorksInfo(Integer.parseInt(id));
      //	System.out.println(flag);
      if (flag) {
        out.println(
            "<script language=\"javascript\">alert('操作成功');window.location.href='manage/works_list.jsp';</script>");
      }
    } else {
      String workaddr = "";
      SmartUpload mySmartUpload = new SmartUpload();
      mySmartUpload.initialize(this.getServletConfig(), request, response);
      String newFileName = "";
      try {
        mySmartUpload.upload();
        newFileName = mySmartUpload.getRequest().getParameter("imgname");

        com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
        String tmpNm = myFile.getFileName();
        String myFileName = new String(myFile.getFileName().getBytes("GBK"), "UTF-8");
        if (!myFileName.equals("")) { // 重新上传文件
          int k = tmpNm.lastIndexOf(".");
          String fileType = tmpNm.substring(k + 1, tmpNm.length());
          String saveImagePath = request.getRealPath("/") + "upload/images/";
          newFileName = System.currentTimeMillis() + "." + fileType;
          if (!new File(saveImagePath).exists()) new File(saveImagePath).mkdirs();

          String saveImageMiniPath = request.getRealPath("/") + "upload/minimages/";
          if (!new File(saveImageMiniPath).exists()) new File(saveImageMiniPath).mkdirs();

          String saveImageBigPath = request.getRealPath("/") + "upload/bigimages/";
          if (!new File(saveImageBigPath).exists()) new File(saveImageBigPath).mkdirs();

          String saveImageUrl = "/upload/images/";
          String savaImageMinUrl = "/upload/minimages/";
          String savaImageBigUrl = "/upload/bigimages/";
          myFile.saveAs(saveImageUrl + newFileName);

          ImageZoom iz = new ImageZoom();
          iz.s_pic100(
              request.getRealPath("/") + saveImageUrl,
              request.getRealPath("/") + savaImageMinUrl,
              newFileName,
              newFileName,
              80,
              100,
              true);
          iz.s_pic300(
              request.getRealPath("/") + saveImageUrl,
              request.getRealPath("/") + savaImageBigUrl,
              newFileName,
              newFileName,
              635,
              520,
              true);
        }

      } catch (SmartUploadException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (newFileName != null || !newFileName.equals("")) {
        // String workaddr="";
        String title = mySmartUpload.getRequest().getParameter("title").trim();
        String author = mySmartUpload.getRequest().getParameter("author").trim();
        String detail = mySmartUpload.getRequest().getParameter("detail").trim();
        String types = mySmartUpload.getRequest().getParameter("types").trim();
        String work_id = mySmartUpload.getRequest().getParameter("works_id");
        if (types.equals("flv")) {
          workaddr = mySmartUpload.getRequest().getParameter("workaddr");
        }

        Works_info works = new Works_info();
        works.setWorks_author(author);
        works.setWorks_file_name(newFileName);
        works.setWorks_recommond(detail);
        works.setWorks_title(title);
        works.setWorks_type(types);
        works.setWorks_addr(workaddr);
        works.setWorks_id(Integer.parseInt(work_id));

        boolean flag = worksInfoLogic.editWorksInfo(works);
        if (flag) {
          out.println(
              "<script language=\"javascript\">alert('编辑成功');window.location.href='manage/works_list.jsp';</script>");
        }
      }
    }
    out.flush();
    out.close();
  }
Example #7
0
  /**
   * Valida los p�rametros entrada y ejecuta los servicios de alta, baja o cambio.
   *
   * @param registro Parametros que se recogen de la sesion del usuario y se le envian a la clase
   *     CON. Estos par�metros son: CVE_GPO_EMPRESA (Clave del grupo empresa), CVE_USUARIO_BITACORA
   *     (clave del usuario que realiza la operacion), RegistroOriginal (registro leido
   *     originalmente y se utiliza cuando se ejecuta la operaci�n de modificacion y se verifica que
   *     no se hallan realizado modificaciones al registro).
   * @param request Objeto que provee de informaci�n al servlet sobre el request del cliente. El
   *     contenedor de servlets crea un objeto HttpServletRequest y lo env�a como un par�metro a
   *     este m�todo.
   * @param response Objeto que provee de informaci�n del servlet sobre el response del cliente. El
   *     contenedor de servlets crea un objeto HttpServletResponse y lo env�a como un par�metro a
   *     este m�todo.
   * @param config Objeto que provee de informaci�n del servlet sobre el ServletConfig del cliente.
   *     El contenedor de servlets crea un objeto ServletConfig y lo env�a como un par�metro a este
   *     m�todo.
   * @param catalogoSL Instancia del Ejb CatalogoSL que ejecuta en la base de datos las operaciones
   *     especificadas en la clase CON
   * @param contexto Objeto que contiene informaci�n acerca del entorno del servidor de
   *     aplicaciones.
   * @param iTipoOperacion Operaci�n que debe ejecutar la clase CON. Las operaciones se encuentran
   *     especificadas en la clase {@link com.rapidsist.portal.cliente.CatalogoControl
   *     CatalogoControl}
   * @return Respuesta del servicio de alta, baja o cambio y la p�gina a donde se redirecciona el
   *     control.
   * @throws RemoteException Si se gener� un error en el Ejb CatalogoSL.
   * @throws java.lang.Exception Si se gener� un error dentro de la clase CON.
   */
  public RegistroControl actualiza(
      Registro registro,
      HttpServletRequest request,
      HttpServletResponse response,
      ServletConfig config,
      CatalogoSL catalogoSL,
      Context contexto,
      int iTipoOperacion)
      throws RemoteException, Exception {
    RegistroControl registroControl = new RegistroControl();

    Object referencia = contexto.lookup("java:comp/env/ejb/PublicacionSL");
    PublicacionSLHome publicacionHome =
        (PublicacionSLHome) PortableRemoteObject.narrow(referencia, PublicacionSLHome.class);
    PublicacionSL publicacion = publicacionHome.create();

    // OBTIENE LOS DATOS DEL USUARIO
    HttpSession session = request.getSession(true);
    Usuario usuario = (Usuario) session.getAttribute("Usuario");
    registro.addDefCampo("CVE_PORTAL", usuario.sCvePortal);
    registro.addDefCampo("CVE_USUARIO", usuario.sCveUsuario);

    Date dFecha = new Date();
    // ESTE OBJETO ES NECESARIO PARA INICIALIZAR EL OBJETO QUE PERMITE GUARDAR LOS ARCHIVOS
    int iResultadoSave = 0; // VARIABLE CON EL VALOR RESULTANTE DE GUARDAR EL ARCHIVO
    // INSTANCIA LA CLASE SE REALIZA EL UPLOAD
    SmartUpload mySmartUpload = new SmartUpload();
    // INICIALIZA EL UPLOAD
    mySmartUpload.initialize(config, request, response);
    // REALIZA LA CARGA DEL O DE LOS ARCHIVOS
    mySmartUpload.upload();
    // SALVA EL ARCHIVO CON EL NOMBRE ORIGINAL DENTRO DEL SERVIDOR
    Files archivos = mySmartUpload.getFiles();

    // OBTIENE LOS VALORES DE LOS PARAMETROS
    java.util.Enumeration e = mySmartUpload.getRequest().getParameterNames();

    String sUrlImagenAnterior = "";
    String sUrlImagenReferencia = "";
    String sUrlTamanoOriginal = "";
    String sUrlTamanoAnterior = "";
    String sUrlVideoAnterior = "";
    String sTamano = "";
    String sAutoPlay = "";
    String sUrlOpcionAutoPlayAnterior = "";

    // OBTIENE LOS PARAMETROS DE LA PAGINA
    while (e.hasMoreElements()) {
      String name = (String) e.nextElement();
      String value = mySmartUpload.getRequest().getParameter(name);
      // ASIGNA EL VALOR AL REGISTRO QUE SE VA A DAR DE ALTA EN LA
      // BASE DE DATOS

      if (name.equals("CveSeccion")) {
        registro.addDefCampo("CVE_SECCION", value);
      }
      if (name.equals("IdPublicacion")) {
        registro.addDefCampo("ID_PUBLICACION", value);
      }
      if (name.equals("IdNivelAcceso")) {
        registro.addDefCampo("ID_NIVEL_ACCESO", value);
      }
      if (name.equals("NomPublicacion")) {
        registro.addDefCampo("NOM_PUBLICACION", value);
      }
      if (name.equals("TxComentario")) {
        registro.addDefCampo("TX_COMENTARIO", value);
      }
      if (name.equals("DescPublicacion")) {
        registro.addDefCampo("DESC_PUBLICACION", value);
      }
      if (name.equals("IdPrioridad")) {
        registro.addDefCampo("ID_PRIORIDAD", value);
      }
      if (name.equals("FIniVigencia")) {
        dFecha = Fecha2.toDate(value);
        registro.addDefCampo("F_INI_VIGENCIA", Fecha2.formatoBDStatic(dFecha));
      }
      if (name.equals("FFinVigencia")) {
        dFecha = Fecha2.toDate(value);
        registro.addDefCampo("F_FIN_VIGENCIA", Fecha2.formatoBDStatic(dFecha));
      }
      if (name.equals("OperacionCatalogo")) {
        registro.addDefCampo("OPERACION_CATALOGO", value);
      }
      if (name.equals("rbTamano")) {
        registro.addDefCampo("TAMANO", value);
        sTamano = value;
      }
      if (name.equals("OperacionCatalogo")) {
        registro.addDefCampo("OPERACION_CATALOGO", value);
      }
      if (name.equals("UrlImagenAnterior")) {
        sUrlImagenAnterior = value;
      }
      if (name.equals("UrlVideoAnterior")) {
        sUrlVideoAnterior = value;
      }
      if (name.equals("UrlTamanoAnterior")) {
        sUrlTamanoAnterior = value;
      }
      if (name.equals("UrlTamanoOriginal")) {
        sUrlTamanoOriginal = value;
      }
      if (name.equals("rbAutoPlay")) {
        registro.addDefCampo("AUTO_PLAY", value);
        sAutoPlay = value;
      }
      if (name.equals("UrlOpcionAutoPlayAnterior")) {
        sUrlOpcionAutoPlayAnterior = value;
      }
    }

    // OBTIENE EL DIRECTORIO RAIZ
    String sRaiz = getRoot(System.getProperty("user.dir"));

    // RUTA DONDE ALMACENA EL ARCHIVO
    String sRutaCompleta =
        sRaiz
            + "Desarrollo"
            + System.getProperty("file.separator")
            + "Cuentas"
            + System.getProperty("file.separator")
            + "Rapidsist"
            + System.getProperty("file.separator")
            + "Servidores"
            + System.getProperty("file.separator")
            + "jboss"
            + System.getProperty("file.separator")
            + "Portal"
            + System.getProperty("file.separator")
            + "deploy"
            + System.getProperty("file.separator")
            + "Portal"
            + System.getProperty("file.separator")
            + "portal.war"
            + System.getProperty("file.separator")
            + "Portales"
            + System.getProperty("file.separator")
            + "Icmar"
            + System.getProperty("file.separator")
            + "stream"
            + System.getProperty("file.separator")
            + "video";

    // SE INICIALIZA LA VARIABLE DEL NOMBRE DEL ARCHIVO QUE CONTIENE EL VIDEO
    String sNombreArchivoVideo = null;

    // SE OBTIENE EL PRIMER ARCHIVO
    File archivo = archivos.getFile(0);

    // SE OBTIENE EL NOMBRE DEL PRIMER ARCHIVO QUE SE ENVIA EN EL FORMULARIO
    sNombreArchivoVideo = archivo.getFileName();

    // SE INICIALIZA LA VARIABLE DEL NOMBRE DEL ARCHIVO QUE CONTIENE LA IMAGEN
    String sNombreArchivoImagen = null;

    // SE OBTIENE EL SEGUNDO ARCHIVO
    File archivo_imagen = archivos.getFile(1);

    // SE OBTIENE EL NOMBRE DEL ARCHIVO QUE CONTIENE EL STREAM
    sNombreArchivoImagen = archivo_imagen.getFileName();

    // ALMACENA LOS ARCHIVOS
    iResultadoSave = mySmartUpload.save(sRutaCompleta);

    registro.addDefCampo("VIDEO", sNombreArchivoVideo);
    registro.addDefCampo("URL_PUBLICACION", sNombreArchivoVideo);
    registro.addDefCampo("URL_IMAGEN", sNombreArchivoImagen);

    if (sNombreArchivoVideo.equals("")) {
      sNombreArchivoVideo = sUrlVideoAnterior;
      registro.addDefCampo("VIDEO", sNombreArchivoVideo);
    }

    if (sNombreArchivoImagen.equals("")) {
      sNombreArchivoImagen = sUrlImagenAnterior;
      registro.addDefCampo("URL_IMAGEN", sNombreArchivoImagen);
    }

    if (sNombreArchivoImagen.equals("")) {
      registro.addDefCampo("URL_IMAGEN", " ");
    }

    if (sTamano.equals("")) {
      sTamano = sUrlTamanoAnterior;
      registro.addDefCampo("TAMANO", sTamano);
    }

    if (sAutoPlay.equals("")) {
      sAutoPlay = sUrlOpcionAutoPlayAnterior;
      registro.addDefCampo("AUTO_PLAY", sAutoPlay);
    }

    if (sAutoPlay.equals("")) {
      registro.addDefCampo("AUTO_PLAY", "No");
    }

    if ((sNombreArchivoVideo.equals("")) || (sTamano.equals(""))) {

      com.rapidsist.portal.catalogos.ResultadoCatalogo resultadoCatalogoControlado =
          new com.rapidsist.portal.catalogos.ResultadoCatalogo();
      resultadoCatalogoControlado.mensaje.setClave("PUBLICACION_NO_ENVIA_ARCHIVO");
      resultadoCatalogoControlado.mensaje.setTipo("Error");
      resultadoCatalogoControlado.mensaje.setDescripcion(
          "Por favor seleccione el archivo de video que desea publicar o/y el tama�o de la pantalla...");
      registroControl.resultadoCatalogo = resultadoCatalogoControlado;
    } else {

      // ES BAJA
      if (registro.getDefCampo("OPERACION_CATALOGO").equals("BA")) {
        String sArchivoVideo =
            sRutaCompleta
                + System.getProperty("file.separator")
                + (String) registro.getDefCampo("VIDEO");
        String sArchivoVideoImagen =
            sRutaCompleta
                + System.getProperty("file.separator")
                + (String) registro.getDefCampo("URL_IMAGEN");

        // SE BORRAN LOS ARCHIVOS DE AUDIO
        BorraPublicacion borraPublicacion = new BorraPublicacion();
        borraPublicacion.BorraArchivo(sArchivoVideo);
        borraPublicacion.BorraArchivo(sArchivoVideoImagen);

        boolean bExito =
            publicacion.BorraObjetoJNDI(
                usuario.sCveGpoEmpresa, usuario.sCvePortal, usuario.sCveUsuario);
      }

      // DIRECCIONA A LA JSP
      registroControl.sPagina =
          "/ProcesaCatalogo?Funcion=PublicacionesVideo&OperacionCatalogo=IN&Filtro=Todos";

      registroControl.resultadoCatalogo =
          catalogoSL.modificacion("PublicacionesVideo", registro, iTipoOperacion);
    }
    return registroControl;
  }
Example #8
0
  public synchronized void service(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    HttpSession dbSession = request.getSession();
    JspFactory _jspxFactory = JspFactory.getDefaultFactory();
    PageContext pageContext =
        _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
    ServletContext dbApplication = dbSession.getServletContext();

    try {
      // 实例化

      HttpSession session = request.getSession();
      ServletContext context = session.getServletContext();
      String path = context.getRealPath("/");
      counter count = new counter(dbApplication);
      SmartUpload mySmartUpload = new SmartUpload();
      mySmartUpload.setCharset("UTF-8");
      nseer_db_backup1 oa_db = new nseer_db_backup1(dbApplication);
      if (oa_db.conn((String) dbSession.getAttribute("unit_db_name"))) {

        getAttachmentLength getAttachmentLength = new getAttachmentLength();
        getAttachmentType getAttachmentType = new getAttachmentType();
        double d =
            getAttachmentLength.getAttachmentLength(
                (String) dbSession.getAttribute("unit_db_name"), "document_config_public_char");
        String ee =
            getAttachmentType.getAttachmentType(
                (String) dbSession.getAttribute("unit_db_name"), "document_config_public_char");
        mySmartUpload.initialize(pageContext);
        mySmartUpload.upload();
        String[] file_name = new String[mySmartUpload.getFiles().getCount()];
        int j = 0;

        int filenum1 =
            count.read((String) dbSession.getAttribute("unit_db_name"), "oaMessagecount");
        String message_ID = filenum1 + "";
        count.write((String) dbSession.getAttribute("unit_db_name"), "oaMessagecount", filenum1);
        String sql1 = "select * from oa_message where message_ID='" + message_ID + "'";
        ResultSet rs = oa_db.executeQuery(sql1);
        if (j != 0 || rs.next()) {

          response.sendRedirect("oa/message/register_ok_a.jsp");
        } else {

          String subject = mySmartUpload.getRequest().getParameter("subject");
          String message_type = mySmartUpload.getRequest().getParameter("message_type");
          String register = mySmartUpload.getRequest().getParameter("register");
          String register_ID = mySmartUpload.getRequest().getParameter("register_ID");
          String register_time = mySmartUpload.getRequest().getParameter("register_time");
          String bulletin = mySmartUpload.getRequest().getParameter("bulletin");

          String content = exchange.toHtmlFCK(mySmartUpload.getRequest().getParameter("content"));

          String bodyab =
              new String(
                  mySmartUpload.getRequest().getParameter("remark").getBytes("UTF-8"), "UTF-8");
          String remark = exchange.toHtml(bodyab);
          if (j != 0) {

            response.sendRedirect("oa/message/register_ok_c.jsp");
          } else {
            String sqla = "";
            String sqlb = "";
            if (bulletin == null) {
              sqla =
                  "insert into oa_message(register,register_ID,register_time,message_ID,subject,type,content,remark";
              sqlb =
                  ") values ('"
                      + register
                      + "','"
                      + register_ID
                      + "','"
                      + register_time
                      + "','"
                      + message_ID
                      + "','"
                      + subject
                      + "','"
                      + message_type
                      + "','"
                      + content
                      + "','"
                      + remark
                      + "'";
            } else {
              sqla =
                  "insert into oa_message(register,register_ID,register_time,message_ID,subject,type,content,remark,check_tag";
              sqlb =
                  ") values ('"
                      + register
                      + "','"
                      + register_ID
                      + "','"
                      + register_time
                      + "','"
                      + message_ID
                      + "','"
                      + subject
                      + "','"
                      + message_type
                      + "','"
                      + content
                      + "','"
                      + remark
                      + "','2'";
            }

            String sql = sqla + sqlb + ")";
            oa_db.executeUpdate(sql);

            response.sendRedirect("oa/message/register_ok_b.jsp");
          }
        }
        oa_db.commit();
        oa_db.close();
      } else {
        response.sendRedirect("error_conn.htm");
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }