public org.json.JSONObject baseUpLoadFile(HttpServletRequest request, HttpServletResponse response, Map map) throws IOException, FileUploadException {
    org.json.JSONObject jsonObject = new org.json.JSONObject();
    String filename = “”;
    response.setContentType(“text/html”);
    // 创建文件项目工厂对象
    DiskFileItemFactory factory = new DiskFileItemFactory();
    // 获取系统默认的临时文件保存路径,该路径为Tomcat根目录下的temp文件夹
    String temp = System.getProperty(“;
    // 设置缓冲区大小为 5M
    factory.setSizeThreshold(1024 1024 5);
    // 设置临时文件夹为temp
    factory.setRepository(new File(temp));
    // 用工厂实例化上传组件,ServletFileUpload 用来解析文件上传请求
    ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
    // 解析结果放在List中
    try {
    List list = servletFileUpload.parseRequest(request);
    for (FileItem item : list) {
    String name = item.getFieldName();
    InputStream is = item.getInputStream();
    if (map == null) {
    if (name.contains(“card_type”)) {
    jsonObject.put(“card_type”, inputStream2String(is));
    }
    if (name.contains(“file”)) {
    try {
    if (map == null) {
    filename = DateTime.getNowString(“yyyyMMddHHmmssSSS”) + “.jpg”;
    inputStream2File(is, request.getSession().getServletContext().getRealPath((new ImgFilePath()).getProperty(“temp”)) + “\“ + filename);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    jsonObject.put(“filename”, filename);
    }
    }
    else if (map != null && map.containsKey(“report”)) {
    String reportfilename = “”;
    String subdir = “”;
    if (item.getFieldName().contains(“reportfilename”)) {
    jsonObject.put(“reportfilename”, inputStream2String(item.getInputStream()));
    }
    if (item.getFieldName().contains(“subdir”)) {
    jsonObject.put(“subdir”, inputStream2String(item.getInputStream()));
    }
    if (name.contains(“zfile”)) {
    try {
    if (!jsonObject.get(“reportfilename”).equals(“”)) {
    if (!jsonObject.get(“subdir”).equals(“”)) {
    inputStream2File(is, request.getSession().getServletContext().getRealPath(“/toyorReport”) + “\“ + jsonObject.get(“subdir”) + “\“ + jsonObject.get(“reportfilename”).toString());
    } else {
    inputStream2File(is, request.getSession().getServletContext().getRealPath(“/toyorReport”) + “\“ + jsonObject.get(“reportfilename”).toString());
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    }
    return jsonObject;
    } catch (FileUploadException e) {
    e.printStackTrace();
    return null;
    } catch (Exception e) {
    e.printStackTrace();
    return null;
    }
    }