附件上传

来源:互联网 发布:php端口号 编辑:程序博客网 时间:2024/04/29 13:00
public ModelAndView uploadAtt(HttpServletRequest request,HttpServletResponse response) throws FileUploadException, IOException, InterruptedException{String submitaction = "";String returnurl = "";String _taskName = "";String taskId = "";String _schemaId = "";String sessionUserName = "";String toDept = "";User user=(User)request.getSession().getAttribute("user");String docId = "";String uploadFiletype = "";String uploadFilename = "";DiskFileUpload fu = new DiskFileUpload();fu.setSizeThreshold(4096);List fileItems = fu.parseRequest(request);Iterator itor = fileItems.iterator();byte[] uploadContent = null;while (itor.hasNext()) {FileItem item = (FileItem) itor.next();if (item.isFormField() == false) {// 如果是上传文件String uploadFilesuffix = ""; // 附件的后缀名uploadContent = item.get();uploadFiletype = item.getContentType();// 文件类型uploadFilename = item.getName();// 完整的文件名,例如:d:/test.docif (!"".equals(uploadFilename)) {uploadFilesuffix = uploadFilename.substring(uploadFilename.lastIndexOf("."), uploadFilename.length());// 文件后缀,例如:doc}uploadFilename=uploadFilename.substring(uploadFilename.lastIndexOf(File.separator)+1);} else {// 如果不是上传文件if ("docId".equals(item.getFieldName())) {docId = new String(item.getString().getBytes("ISO-8859-1"),"GBK");}if("returnurl".equals(item.getFieldName())){returnurl = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");}if("submitaction".equals(item.getFieldName())){submitaction = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");}if("nodeName".equals(item.getFieldName())){_taskName = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");}if("taskId".equals(item.getFieldName())){taskId = new String(item.getString().getBytes("ISO-8859-1"),"GBK");}if("schemaId".equals(item.getFieldName())){_schemaId = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");}if("signUserName".equals(item.getFieldName())){sessionUserName = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");}}}}


原创粉丝点击