이 기사는 참조를 위해 Javaweb 파일 포장 및 배치 다운로드의 예를 공유했습니다. 특정 내용은 다음과 같습니다
// 배치 다운로드 Unresolved job @requestmapping (value = "/downloadallhomework", method = requestmethod.get) public void downloadallhomework (httpsession httpsession, httpservletrequest 요청, httpservletresponse 응답, string assentmentid, int classcode) {site site = (site) String siteId = site.getId (); // 작업 ID를 기반으로 작업 세부 사항을 얻습니다. 과제를 할당 할당 할당됩니다. 과제를 할당합니다. GenerateParameters (antlymentDetail); // 정보가 불완전하고 나중에 채워야합니다. list <antlesmentServiceWs.getSubMitedAsSignmentStudent (antlymentId); // 모든 제출 목록을 가져옵니다. <string> submitids = new ArrayList <string> (); for (int i = 0; i <antlissUbmitList.size (); i ++) {String olds olds oldmentSubmitList.get (i) .getId (); if (submitid == null || submitid == "") 계속; submitids.add (submitid); } // 제출 세부 정보 가져 오기 목록 <할당 ablitsubMits = new ArrayList <할당 <dansmentSubmit> (); for (문자열 a : submitIds) {ansassmentSubmit as = antlymentservicews.getSubmitAssignment (a); ansademmentsubmits.add (as); } // 과제를 제출 한 각 학생을 맵, 사용자 이름-> 할당 hashmap = new Hashmap <string, ansassmentubmit> (); for (antsammentsUbmit antlymentSubmit : antlasmentSubMits) {String windentId = ansassUbmit.getUername (); whitudLubmitMap.put (StudentId, antlasmentSubmit); } // 클래스 번호에 따라 수업에서 모든 학생의 학생 ID를 얻은 다음 학생 ID 목록 <AdentsMentSubmit> ansassmentStudEntList = new ArrayList <할당 <할당 문서프미트> ()를 기반으로 세부 목록을 얻습니다. List <Membovo> StudentList = memberservicews.getStudents (siteId, classCode); for (membervo student : studentlist) {String username = whient.getId (); 문자열 realName = whiting.getName (); 과제를 antlicmittubmit = new antlicmentsUbmit (); if (withy studentUbmitMap.get (username)! = null) {ansassmentubmit = whitesubmitmap.get (username); } antlicmentSubmit.setRealName (realName); 과제를 찍는 사람 (사용자 이름); generatea (과제 배출); 할당 studentList.add (ansassmentSubmit); } list <할당 abmit> 제출 목록 = new ArrayList <할당 부문> (); for (assegradementList) {if (as.getGradePoint () == null && as.getAsSignMentId ()! = null) admpertedList.Add (as); } list <file> files = new ArrayList <file> (); 파일 = 새 파일 ( "d : /css.rar"); if (! file.exists ()) {file.createnewfile (); } response.reset (); // response.getWriter () // 파일 생성 출력 스트림 파일 OutputStream fus = 새 FileOutputStream (파일); // 패키지 메소드에서는 ZipOutputStream과 같은 출력 스트림을 사용하므로 출력 스트림 ZipOutputStream Zipout = New ZipoutputStream (FOUS)을 변환합니다. for (adentmentSubmit a : admittedList) {for (attachids aa : a.getattachids ()) {try {string fileId = aa.getId (); String CloudFileUrl = "http://xxx.xxx.xxx.xxx:8066/imageservice/downloadfile/"; String fileUrl = ranticementService.getAtTachmentByFileId (fileId) .getUrlupload (); fileUrl = fileUrl.SubString (fileUrl.lastIndexof ( "/") + 1); fileUrl = CloudFileUrl + fileUrl; String filename = anticementService.getAttAchmentByFileId (fileId) .getName (); // 원격 파일의 파일 이름을 가져옵니다. // response.addheader ( "content-disposition", "attachment; filename =" + // new String (filename.getBytes ( "gbk"), "iso-8859-1")); // iso-8859-1 zipentry entry = new Zipentry (new String (filename.getBytes ( "gbk"), "iso-8859-1"); zipout.putnextentry (Entry); url urlfile = null; httpurlconnection httpurl = null; urlfile = new URL (fileUrl); httpurl = (httpurlConnection) urlfile.openConnection (); httpurl.connect (); inputStream downloadFile = httpurl.getInputStream (); int len = 0; 바이트 [] buf = 새로운 바이트 [1024]; while ((len = downloadfile.read (buf, 0, 1024))! = -1) {zipout.write (buf, 0, len); }} catch (jsonexception e) {e.printstacktrace (); } catch (UnsupportedEncodingException e) {e.printstacktrace (); }}}} zipout.close (); fous.close (); DownloadZip (파일, 응답); } // 허용 된 모든 파일을 압축 패키지로 만듭니다. 공개 정적 httpservletResponse downloadzip (파일 파일, httpservletResponse 응답) {try {// 스트림 형식으로 파일을 다운로드하십시오. inputStream fis = new bufferedInputStream (new FileInputStream (file.getPath ())); 바이트 [] buffer = new Byte [fis.available ()]; fis.read (버퍼); fis.close (); // 응답 응답을 클리어. reset (); outputStream toclient = new bufferedOutputStream (response.getOutputStream ()); Response.setContentType ( "Application/Octet-stream"); // 출력이 중국어 이름을 가진 파일 인 경우 urlencoder.encode 메서드를 사용하여 응답을 처리해야합니다. toclient.write (버퍼); toclient.flush (); toclient.close (); } catch (ioexception ex) {ex.printstacktrace (); } 마침내 {try {file f = 새 파일 (file.getPath ()); f.delete (); } catch (예외 e) {e.printstacktrace (); }} 반환 응답; }블로그 주소! http://oldriver.top/ 오래된 운전자의 기술 매뉴얼
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.