一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務(wù)器之家 - 編程語言 - JAVA教程 - javaweb文件打包批量下載代碼

javaweb文件打包批量下載代碼

2020-05-22 10:39acmjk JAVA教程

這篇文章主要為大家詳細(xì)介紹了javaweb文件打包批量下載代碼,批量下載未批改作業(yè),感興趣的小伙伴們可以參考一下

本文實例為大家分享了javaweb文件打包批量下載,供大家參考,具體內(nèi)容如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// 批量下載未批改作業(yè)
 @RequestMapping(value = "/downloadAllHomework", method = RequestMethod.GET)
 public void downloadAllHomework(HttpSession httpSession, HttpServletRequest request, HttpServletResponse response, String assignmentid, int classCode) throws Exception {
 
  Site site = (Site) httpSession.getAttribute("site");
  String siteid = site.getId();
 
  // 根據(jù)作業(yè)ID獲取作業(yè)詳細(xì)信息
  AssignmentDetail assignmentDetail = assignmentServiceWS.getAssignmentDetail(assignmentid);
  generateParameters(assignmentDetail);
 
  // 信息不完整,后面需要填充。
  List<AssignmentSubmit> assignmentSubmitList = assignmentServiceWS.getSubmitedAssignmentStudent(assignmentid);
 
  // 獲取所有的submitid
  List<String> submitids = new ArrayList<String>();
  for (int i = 0; i < assignmentSubmitList.size(); i++) {
   String submitid = assignmentSubmitList.get(i).getId();
   if (submitid == null || submitid == "")
    continue;
   submitids.add(submitid);
  }
  // 獲取提交詳情
  List<AssignmentSubmit> assignmentSubmits = new ArrayList<AssignmentSubmit>();
  for (String a : submitids) {
   AssignmentSubmit as = assignmentServiceWS.getSubmitAssignment(a);
   assignmentSubmits.add(as);
  }
  // 給每個已提交作業(yè)的學(xué)生配一個map,userName-->AssignmentSubmit
  Map<String, AssignmentSubmit> studentSubmitMap = new HashMap<String, AssignmentSubmit>();
  for (AssignmentSubmit assignmentSubmit : assignmentSubmits) {
   String studentID = assignmentSubmit.getUserName();
   studentSubmitMap.put(studentID, assignmentSubmit);
  }
  // 根據(jù)班級號獲取該班所有學(xué)生的學(xué)號,再根據(jù)學(xué)號獲取詳情列表
  List<AssignmentSubmit> assignmentStudentList = new ArrayList<AssignmentSubmit>();
 
  List<MemberVO> studentList = memberServiceWS.getStudents(siteid, classCode);
  for (MemberVO student : studentList) {
 
   String userName = student.getId();
   String realName = student.getName();
   AssignmentSubmit assignmentSubmit = new AssignmentSubmit();
   if (studentSubmitMap.get(userName) != null) {
    assignmentSubmit = studentSubmitMap.get(userName);
   }
   assignmentSubmit.setRealName(realName);
   assignmentSubmit.setUserName(userName);
   generateA(assignmentSubmit);
   assignmentStudentList.add(assignmentSubmit);
  }
 
  List<AssignmentSubmit> submitedList = new ArrayList<AssignmentSubmit>();
  for (AssignmentSubmit as : assignmentStudentList) {
   if (as.getGradePoint() == null && as.getAssignmentID() != null)
    submitedList.add(as);
  }
 
  List<File> files = new ArrayList<File>();
 
  File file = new File("d:/css.rar");
  if (!file.exists()) {
   file.createNewFile();
  }
  response.reset();
  // response.getWriter()
  // 創(chuàng)建文件輸出流
  FileOutputStream fous = new FileOutputStream(file);
 
  // 打包的方法我們會用到ZipOutputStream這樣一個輸出流, 所以這里我們把輸出流轉(zhuǎn)換一下
 
  ZipOutputStream zipOut = new ZipOutputStream(fous);
  for (AssignmentSubmit a : submitedList) {
 
   for (AttachIDs aa : a.getAttachIDs()) {
    try {
     String fileId = aa.getId();
     String cloudFileUrl = "http://xxx.xxx.xxx.xxx:8066/ImageService/DownloadFile/";
     String fileUrl = announceService.getAttachmentByFileid(fileId).getUrlUpload();
     fileUrl = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
     fileUrl = cloudFileUrl + fileUrl;
     String fileName = announceService.getAttachmentByFileid(fileId).getName(); // 獲取遠(yuǎn)程文件的文件名。
     // 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);
 }
 // 把接受的全部文件打成壓縮包
 public static HttpServletResponse downloadZip(File file, HttpServletResponse response) {
  try {
   // 以流的形式下載文件。
   InputStream fis = new BufferedInputStream(new FileInputStream(file.getPath()));
   byte[] buffer = new byte[fis.available()];
   fis.read(buffer);
   fis.close();
   // 清空response
   response.reset();
   OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
   response.setContentType("application/octet-stream");
 
   // 如果輸出的是中文名的文件,在此處就要用URLEncoder.encode方法進(jìn)行處理
   response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
   toClient.write(buffer);
   toClient.flush();
   toClient.close();
  } catch (IOException ex) {
   ex.printStackTrace();
  } finally {
   try {
    File f = new File(file.getPath());
    f.delete();
   } catch (Exception e) {
    e.printStackTrace();
   }
  }
  return response;
 
 }

博客地址!http://oldriver.top/ 老司機(jī)技術(shù)手冊

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲精品久久久久久婷婷 | 日本一道一区二区免费看 | 国产精品资源在线观看网站 | 日韩欧美亚洲国产高清在线 | 午夜DV内射一区区 | 国产精品亚洲综合第一区 | 日本漫画被黄漫免费动 | 国产草草视频 | 亚洲欧美久久久久久久久久爽网站 | 香蕉免费高清完整 | 美女bbxx美女bbb | 日本高清在线看免费观看 | 99欧美精品 | xxnx日本免费护士 | 四虎4hu永久免费国产精品 | 深夜福利影院在线观看 | 天天天天天天天操 | 亚洲欧美视频在线播放 | 91看片淫黄大片欧美看国产片 | 女海盗斯蒂内塔的复仇2免费观看 | 午夜久久久久久网站 | 成品人视频免费观看 | 国产成人在线免费观看 | 1024免费福利永久观看网站 | 亚洲国产在线午夜视频无 | 男人操美女视频 | chinese一tk视频丨vk | 亚洲精品欧洲久久婷婷99 | 五月色婷婷在线影院 | 美国复古性经典xxxxx | 亚洲一区二区精品视频 | 国产精品自在线拍 | 四虎精品永久在线网址 | 精品久久久久久久久免费影院 | 亚洲成人黄色 | 校园情射 | 香港三级血恋3 | 国产免费一区二区三区 | 好大好硬好紧太深了受不了 | 69午夜影院| 日本xxxxx18护士xxx|