You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.5 KiB
Plaintext
88 lines
3.5 KiB
Plaintext
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
|
|
import="java.net.*,java.io.*,websquare.logging.*,websquare.util.*,org.json.simple.*
|
|
,org.json.simple.parser.*,java.util.zip.ZipEntry,java.util.zip.ZipOutputStream"
|
|
%><%
|
|
request.setCharacterEncoding("UTF-8");
|
|
|
|
String req = URLDecoder.decode(HttpUtil.getBase64Parameter(request, "xmlValue"), "UTF-8");
|
|
JSONParser jsonParser = new JSONParser();
|
|
JSONArray jsonArray = (JSONArray)jsonParser.parse(req);
|
|
String fileSep = File.separator;
|
|
|
|
int bufferSize = 1024 * 2;
|
|
ZipOutputStream zos = null;
|
|
String ouputName = "download";
|
|
BufferedInputStream bis = null;
|
|
|
|
try {
|
|
// set header
|
|
response.reset();
|
|
response.setContentType("application/octet-stream; charset=UTF-8;");
|
|
response.setHeader("Content-Transfer-Encoding", "binary;");
|
|
response.setHeader("Pragma", "no-cache;");
|
|
response.setHeader("Expires", "-1;");
|
|
|
|
String userAgent = request.getHeader("User-Agent");
|
|
if ( userAgent.indexOf("MSIE 5.5") > -1 ) { // MS IE 5.5 이하
|
|
ouputName = URLEncoder.encode(ouputName, "UTF-8").replaceAll("\\+","%20");
|
|
} else if ( userAgent.indexOf("MSIE") > -1) { // MS IE (보통은 6.x 이상 가정)
|
|
ouputName = URLEncoder.encode(ouputName, "UTF-8").replaceAll("\\+","%20");
|
|
} else if ( userAgent.indexOf("Chrome") > -1) { // Chrome
|
|
ouputName = new String(ouputName.getBytes("UTF-8"), "ISO-8859-1");
|
|
} else if ( userAgent.indexOf("Firefox") > -1) { // Firefox
|
|
ouputName = new String(ouputName.getBytes("UTF-8"), "ISO-8859-1");
|
|
} else { // 모질라나 오페라
|
|
ouputName = new String(ouputName.getBytes("UTF-8"), "latin1");
|
|
}
|
|
|
|
if (userAgent.indexOf("MSIE 5.5") > -1) {
|
|
response.setHeader("Content-Disposition", "filename=" + ouputName + ".zip" + ";");
|
|
} else {
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + ouputName + ".zip" + ";");
|
|
}
|
|
|
|
// outputstream
|
|
OutputStream os = response.getOutputStream();
|
|
zos = new ZipOutputStream(os); // ZipOutputStream
|
|
zos.setLevel(8); // 압축 레벨 - 최대 압축률은 9, 디폴트 8
|
|
|
|
|
|
// clear for jsp error
|
|
out.clear();
|
|
out = pageContext.pushBody();
|
|
|
|
// get param
|
|
for(int i = 0; i < jsonArray.size(); i++) {
|
|
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
|
|
String fileUrl = (String)jsonObject.get("fileUrl");
|
|
String fileName = (String)jsonObject.get("fileName");
|
|
String realFile = (String)jsonObject.get("realFile");
|
|
File sourceFile = new File(fileUrl+fileSep+fileName);
|
|
|
|
if(sourceFile.exists()){
|
|
bis = new BufferedInputStream(new FileInputStream(sourceFile));
|
|
ZipEntry zentry = new ZipEntry(realFile);
|
|
zentry.setTime(sourceFile.lastModified());
|
|
zos.putNextEntry(zentry);
|
|
|
|
byte[] buffer = new byte[bufferSize];
|
|
int cnt = 0;
|
|
while ((cnt = bis.read(buffer, 0, bufferSize)) != -1) {
|
|
zos.write(buffer, 0, cnt);
|
|
}
|
|
zos.closeEntry();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}catch(RuntimeException e) {
|
|
Logger.exception("[fileDownload.jsp] Exception.", e);
|
|
} catch(Exception e) {
|
|
Logger.exception("[fileDownload.jsp] Exception.", e);
|
|
} finally {
|
|
zos.close();
|
|
bis.close();
|
|
}
|
|
%>
|