この記事では、参照用のJavawebファイルパッケージとバッチダウンロードの例を共有しています。特定のコンテンツは次のとおりです
// batchダウンロード@RequestMapping(value = "/downloadallhomework"、method = requestmethod.get)public downloadallhomework(httpsers httpsesssion、httpservletrequest request、httpservletresponse request、htttpservletresponse response、string、int classcode) string siteid = site.getId(); //ジョブID AssignmentDetail AssignmentDetail = AssignmentServiceWs.GetAssignmentDetail(AssignmentID)に基づいてジョブの詳細を取得します。 GenerateParameters(AssignmentDetail); //情報は不完全であり、後で入力する必要があります。 list <assomentmentsubmitlist = assomentmentservicews.getSubmitedAssignmentStudent(assomentmentid); //すべてのsubmitidリスト<string> submitids = new ArrayList <String>(); for(int i = 0; i <assightmentsubmitlist.size(); i ++){string submentid = assignmentsubmitlist.get(i).getid(); if(submitid == null || submitid == "")継続; submitids.add(submitid); } //送信詳細リスト<Assignmentsubmits> assomintmentsubmits = new ArrayList <AssignmentsUbmit>(); for(string a:submitids){assignmentsubmit as = assignmentservicews.getsubmitasignment(a); assommentsubmits.add(as); } //割り当てを提出した各生徒をマップ、username - > assomintmentsubmitマップ<string、assonementsubmit> sustentubmitmap = new hashmap <string、assomentmentsubmit>(); for(assignmentsubmit assignmentsubmit:assighnmentsubmits){string dustentid = assonementsubmit.getusername(); Studentsubmitmap.put(sustentid、assignmentsubmit); } //クラス番号に従ってクラス内のすべての生徒の学生IDを取得し、学生IDリスト<AssignmentsUbmit> assignmentStudentList = new ArrayList <AssignmentsUbmit>()に基づいて詳細なリストを取得します。 List <MemberVo> StudentList = MemberServiceWs.GetStudents(SiteID、classCode); for(membervo Student:StudentList){string username = dustent.getId(); string realname = sustent.getname(); assightmentsubmit assignmentsubmit = new Assignmentsubmit(); if(sustentsubmitmap.get(username)!= null){assignmentsubmit = dustentialubmitmap.get(username); } assignmentsubmit.setRealName(realName); Assignmentsubmit.setUsername(username); generatea(assommentsubmit); assignmentStudentlist.add(assightmentsubmit); } list <Assignmentsubmit> submittedList = new ArrayList <AssignmentsUbmit>(); for(assignmentsubmit as:assightmentStudentlist){if(as.getGradePoint()== null && as.getAssignmentId()!= null)submittlist.add(as); } list <file> files = new ArrayList <file>(); file file = new file( "d:/css.rar"); if(!file.exists()){file.createNewFile(); } respons.reset(); // Response.getWriter()//ファイル出力Stream FileOutputStream FUS = new FileOutputStream(file); //パッケージ化された方法では、ZipoutputStreamのような出力ストリームを使用するため、ここで出力ストリームZipoutputStream Zipout = new ZipOutputStream(Fous)を変換します。 for(assightmentsubmit a:submittedList){for(aditidids aa:a.getattachids()){try {string fileid = aa.getid(); string cloudfileurl = "http://xxx.xxx.xxx.xxx:8066/imageservice/downloadfile/"; string fileurl = AnncementMentservice.getAttachmentByFileID(fileID).geturlupload(); fileurl = fileurl.substring(fileurl.lastindexof( "/") + 1); fileurl = cloudfileurl + fileurl; string filename = Anncementmentservice.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; byte [] buf = new byte [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(file、response); } //受け入れられたすべてのファイルを圧縮パッケージに公開しますhttpservletResponse downloadzip(ファイル、httpservletResponse応答){try {//ストリームの形式でファイルをダウンロードします。 inputstream fis = new BufferedInputStream(new fileInputStream(file.getPath())); byte [] buffer = new byte [fis.abailable()]; fis.read(buffer); fis.close(); //応答応答をクリアしますResponse.reset(); outputStream toClient = new BufferedOutputStream(Response.GetOutputStream()); Response.setContentType( "Application/Octet-Stream"); //出力が中国名のファイルである場合、urlencoder.encodeメソッドを使用してresponse.setheader( "content-disposition"、 "attachment; filename =" + urlencoder.encode(file.getName()、 "utf-8")); toclient.write(buffer); toclient.flush(); toclient.close(); } catch(ioException ex){ex.printstacktrace(); }最後に{try {file f = new file(file.getPath()); f.delete(); } catch(Exception e){e.printstacktrace(); }}返信応答; }ブログアドレス! http://oldriver.top/古いドライバーの技術マニュアル
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。