<%@page import="java.io.File" %><%@page import="org.apache.commons.io.FileUtils" %><%@page import="com.amarsoft.are.jbo.BizObject" %><%@page import="com.amarsoft.are.jbo.BizObjectManager" %><%@page import="com.amarsoft.are.jbo.JBOFactory" %><%@page import="org.apache.commons.fileupload.FileItem" %><%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %><%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %> <%@ page import="com.amarsoft.are.jbo.JBOException" %> <%@ page import="java.util.regex.Pattern" %> <%@ page import="java.util.regex.Matcher" %> <%@ page contentType="text/html; charset=GBK" %><%@ include file="/IncludeBeginMDAJAX.jsp"%><% //1.创建DiskFileItemFactory对象,配置缓存用 DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(); // 2. 创建 ServletFileUpload对象 ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory); // 3. 设置文件名称编码 servletFileUpload.setHeaderEncoding("utf-8"); List items = servletFileUpload.parseRequest(request); String inputTime = StringFunction.getTodayNow(); //附件编号上传时间 InputStream is = null; //当一次传多个图片时,会多次执行这个页面,下面for循环,只是将参数读取出来,将普通数据封装为map,然后将map传给写入数据库的方法。 Map params = new HashMap<>(); for (FileItem fileItem : items) { if (fileItem.isFormField()) { // >> 普通数据 String fieldValue = fileItem.getString("utf-8"); String fieldName = fileItem.getFieldName(); params.put(fieldName,fieldValue); ARE.getLog().info(fieldName + ": " + fieldValue); } else { //获取文件的实际内容 is = fileItem.getInputStream(); } } //找出配置的存储路径 String sFileSavePath = CurConfig.getConfigure("FileSavePath"); String uuid = java.util.UUID.randomUUID().toString().replaceAll("-", ""); String sFullPath = com.tenwa.officetempalte.util.FileOperatorUtil.getuploadFileDir(sFileSavePath) + uuid + "_" + params.get("name"); params.put("filePath",sFullPath); params.put("inputTime",inputTime); params.put("inputUserId",CurUser.getUserID()); try{ if(Integer.parseInt(params.get("size")) <= 0){ throw new Exception("上传文件失败,请联系管理员!"); } //保存实体文件 FileUtils.copyInputStreamToFile(is, new File(sFullPath)); //保存文件信息 fileInfoSave(params,Sqlca); Sqlca.commit(); }catch (Exception e){ e.printStackTrace(); Sqlca.rollback(); out.print("FAILED"); } %> <%! public void fileInfoSave(Map params,Transaction Sqlca) throws JBOException { if(params.size()>0){ BizObjectManager frfBom = JBOFactory.getBizObjectManager("jbo.oti.FC_REQUEST_FILE",Sqlca); List frfBoList = frfBom.createQuery("DEL_FLAG='0' and FC_REQUEST_ID=:fcRequestId and FC_FLOW_TYPE=:fcFlowType and FC_FILE_CODE=:fcFileCode") .setParameter("fcRequestId",params.get("fcRequestId")).setParameter("fcFlowType",params.get("fcFlowType")).setParameter("fcFileCode",params.get("fcFileCode")).getResultList(true); String fcFlowTypeName = frfBoList.get(0).getAttribute("FC_FLOW_TYPE_NAME").toString(); String fcFileCodeName = frfBoList.get(0).getAttribute("FC_FILE_CODE_NAME").toString(); for(BizObject bo : frfBoList){ bo.setAttributeValue("FC_FILE_STS","2"); bo.setAttributeValue("FC_FILE_STS_DESC","用户添加待补传"); } BizObject frfBo = frfBom.newObject(); frfBo.setAttributeValue("FC_REQUEST_ID",params.get("fcRequestId")); frfBo.setAttributeValue("FC_FLOW_TYPE",params.get("fcFlowType")); frfBo.setAttributeValue("FC_FLOW_TYPE_NAME",fcFlowTypeName); frfBo.setAttributeValue("FC_FILE_CODE",params.get("fcFileCode")); frfBo.setAttributeValue("FC_FILE_CODE_NAME",fcFileCodeName); String fileType = params.get("type"); String fcFileType = fileType.substring(fileType.lastIndexOf("/")+1).toLowerCase(); frfBo.setAttributeValue("FC_FILE_TYPE",fcFileType); frfBo.setAttributeValue("FILE_TYPE",fileType); frfBo.setAttributeValue("FILE_NAME",params.get("name")); frfBo.setAttributeValue("FILE_PATH",params.get("filePath")); frfBo.setAttributeValue("FC_FILE_STS","2"); frfBo.setAttributeValue("FC_FILE_STS_DESC","用户添加待补传"); frfBo.setAttributeValue("CREATE_TIME",params.get("inputTime")); frfBo.setAttributeValue("UPDATE_TIME",params.get("inputTime")); frfBo.setAttributeValue("DEL_FLAG","0"); frfBo.setAttributeValue("INPUTTIME",params.get("inputTime")); frfBo.setAttributeValue("INPUTUSER",params.get("inputUserId")); frfBom.saveObject(frfBo); } } %> <%@ include file="/IncludeEndAJAX.jsp"%>