FileInputStream fin = null;
OutputStream os = null;
File file = null;
String path = "/testServer/voice/";
String fileName = "testFile.exe";
String sFilePath = path + fileName;
try{
file = new File(sFilePath);
fin = new FileInputStream(file);
}catch(FileNotFoundException fnfe){
System.out.println("FILE_ERROR...");
}
response.reset();
if(fin != null){
String agentType = request.getHeader("User-Agent");
if (agentType.indexOf("MSIE 5.5") != -1){
System.out.println("MSIE 5.5");
response.setContentType("doesn/matter; charset=UTF-8;");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ";");
}else{
response.setContentType("application/smnet");
response.setHeader("Content-Type", "application/x-msdownload; charset=UTF-8;");
response.setHeader("Content-Disposition","attachment; filename=" + fileName + ";");
System.out.println("MSIE ELSE ");
}
response.setHeader("Content-Transfer-Encoding","binary;");
response.setHeader("Content-Length",""+file.length());
response.setHeader("Pragma","no-cache;");
response.setHeader("Expires","-1;");
os = response.getOutputStream();
byte[] abStream = new byte[4096];
int leng = 0;
while((leng = fin.read(abStream)) > 0){
os.write(abStream, 0, leng);
}
}else{
response.getWriter().println("<script language='javascript'>");
response.getWriter().println("alert(\"실패하였습니다.\");");
response.getWriter().println("history.back(-1);");
response.getWriter().println("</script>");
}
'프로그래밍 > JAVA, JSP' 카테고리의 다른 글
자바(JAVA) BASE64 암호화/복호화 (0) | 2013.11.13 |
---|---|
자바(JAVA) 윤달 구하기 (0) | 2013.11.13 |
JSP 달력 만들기 (0) | 2013.11.13 |
JSP 풍선도움말 넣기 (0) | 2013.11.13 |
자바스크립트 체크박스(checkBox) 그룹화 (0) | 2013.11.13 |
댓글