⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mertmodmngservlet.java

📁 培训考试系统代码
💻 JAVA
字号:
package com.huawei.icd30.agt.mertmng;

import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
import javax.servlet.*;
import javax.servlet.http.*;
import com.huawei.icd30.agt.util.*;
import com.huawei.icd30.agt.util.zip.*;
import com.huawei.icd30.common.db.*;
import com.huawei.icd30.agt.configmng.*;
import java.util.StringTokenizer;
import com.huawei.icd30.common.systemconfig.*;


/**
 * <p> 修改资料操作。</p>
 * <p> </p>
 * <p> </p>
 * @author 龙燕茜
 * @version 1.0
 */

public class MertModMngServlet extends HttpServlet
{
    private static final String CONTENT_TYPE = "text/html; charset=gb2312";


    //private  FtpDown ftp = null;

    //Initialize global variables
    public void init() throws ServletException
    {
    }
    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        request.setCharacterEncoding("gb2312");
        response.setContentType(CONTENT_TYPE);

        MultiRequest mr = new MultiRequest(request) ;

        //获取参数值
        String matid = mr.getParameter("matid");
        String title = mr.getParameter("title");

        String keyWord = mr.getParameter("keyWord");
        String abstracts = mr.getParameter("abstracts");
        String classType = mr.getParameter("classType");
        String classId = mr.getParameter("classId");
        String authInfo = mr.getParameter("authInfo");
        String staffNoInfo = mr.getParameter("staffNoInfo");
        String isModFile = mr.getParameter("isModFile");
        String isZip = mr.getParameter("isZip");
        String indexFile = mr.getParameter("indexFile");
        String fileName1 = mr.getParameter("fileName");
        String searchSQL = mr.getParameter("searchSQL");

        //接收文件
        String fullFile = "";
        if("1".equalsIgnoreCase(isModFile))
        {
            File toFile = null ;
            BufferedOutputStream os = null;
            SimpleDateFormat df = new SimpleDateFormat("yyMMddHHmmSSS");
            File filePath = new File(this.getServletContext().getRealPath("agt"));
            String subFilePath = "mertres" + File.separatorChar + classId + File.separatorChar
                             + df.format(new Date());

            String fileName = mr.getFilename();

            String sFileName = "";

            while(fileName!=null && !fileName.trim().equals(""))
            {
                //String suffix = fileName.substring(fileName.lastIndexOf(".") ,fileName.length());
                //String newName = String.valueOf(increase++) + suffix;
                fullFile = subFilePath +  File.separatorChar + fileName;
                sFileName = fileName;
                toFile = new File(filePath , fullFile);

                toFile.getParentFile().mkdirs();
                os = new BufferedOutputStream(
                        new FileOutputStream(toFile));
                mr.upload(os);
                os.close();
                fileName = mr.getFilename() ;
             }

            if("1".equalsIgnoreCase(isZip))
            {//解开压缩包
               ExecuteFile ef = new ExecuteFile();
               String uzFileName = filePath.getPath() + File.separatorChar + fullFile;
               String uzPath = filePath.getPath() + File.separatorChar + subFilePath;


               if(!ef.fileUnZip(uzFileName,uzPath))
               {

                  response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.MERT_UPZIP);
                  return;
               }

               fullFile = subFilePath +  File.separatorChar + indexFile;
               File file = new File(uzFileName);
               file.delete();
            }
            fileName1 = File.separatorChar + "agt" + File.separatorChar +fullFile;
        }

        SysConnPool cspool = null;
        SysDbConn con = null;

        //顶級目录应该可以配置,此处有问题,要求保证目录的层次结构,必须
        //做一个目录,目的是文件按照目录检索的时候

        try
        {

          //操作数据库
          cspool = SysConnPool.getInstance();
          con = cspool.getAplComs();
          con.preparedSP();
          con.setString(1, matid);
          con.setString(2, title);
          con.setString(3, keyWord);
          con.setString(4, abstracts);
          con.setString(5, classType);
          con.setString(6, fileName1);
          con.setString(7, classId);
          con.setString(8, authInfo);
          con.setString(9, staffNoInfo);

          SysRecord res = con.csCommonSP("P_Agt_MaterUpdate").getParamSet();

          if (res.getInt(0) != 0)
          {
              response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.MERT_MOD);
              return;
          }
        }
        catch (SysDbException e)
        {
           e.printStackTrace();
           response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.COMMONSERVICE_ERROR);
           return;
        }
        catch (java.sql.SQLException e)
        {
           e.printStackTrace();
           response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.DATABASE_ERROR);
           return;
        }
       catch(IOException ioe)
       {
           ioe.printStackTrace();
           response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.FILE_EORROR);
           return;
       }
       catch(SecurityException se)
       {
           se.printStackTrace();
           response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.FILE_SECURITY_EORROR);
           return;
       }
       catch(Exception e)
       {//捕获未知异常,定向到出错页面
           e.printStackTrace();
           response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.UNKNOW_ERROR);
           return;
       }
       finally
       {
          con.close();
       }

       //成功页面提示成功信息后,自动重新查询
       request.getSession().setAttribute("searchSQL",searchSQL);
       response.sendRedirect("/agt/mertmng/MertMngSuccess.jsp?successId=" + SuccessCode.MERTMNG_SAVE );
       return;
    }





 //Clean up resources
    public void destroy()
    {
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -