<%
/**
* @(#) download.jsp @version 2009. 12. 29.
*
*/%>
<%@ page contentType="text/html;charset=euc-kr" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%!
public String getValue(String psValue){
return (psValue != null ? (psValue.equals("null") ? "" : psValue) : "");
}
public String pathValidate(String value){
if(value == null || value.length() < 1)
return value;
try {
if(value.indexOf("../") > -1) {
value = value.replaceAll(".[.]/", "");
}
else if(value.indexOf("..\\") > -1) {
value = value.replaceAll(".[.]\\\\", "");
}
}catch(Exception ex) {
//ex.printStackTrace();
}
return value;
}
%>
<%
String strFileName = request.getParameter("fileName")!=null?request.getParameter("fileName"):"";
String strDir = request.getParameter("fileDir")!=null?request.getParameter("fileDir"):"";
String strMsg = "";
if( strFileName.indexOf("\\") > -1 ){ out.print("접근할수 없는 경로입니다."); return; }
if( strFileName.indexOf(".jsp") > -1 ){ out.print("접근할수 없는 경로입니다."); return; }
//if( strDir.indexOf("\\") > -1 ){ out.print("접근할수 없는 경로입니다."); return; }
//if( strDir.indexOf(".jsp") > -1 ){ out.print("접근할수 없는 경로입니다."); return; }
String strFileName1 = "";
String strFilePath = "";
strFilePath = "";//PropertyManager.getProperty(WebCommon.WEB_BIZ_PROP, "FILE_UPLOAD_PATH");
if( !strDir.equals("") ){
//strDir = strDir.replaceAll("/", "");
strFilePath = strFilePath + strDir;
}
String strFileFullPath=strFilePath+strFileName;
//strFileFullPath="http://192.168.1.44:8081/hkm/VersionHistory.txt";
//strFileFullPath="/home/vmail/tomcat_kms_test/webapps/hkm/VersionHistory.txt";
out.println(strFileFullPath);
byte[] buffer = new byte[4096];
File fileSave = new File(strFileFullPath);
// InputStream isFile = null;
ServletOutputStream osOut = null;
out.println(fileSave.getParent()+"+++"+fileSave.getName());
try{
URL url = new URL(strFileFullPath);
URLConnection uc = url.openConnection();
String contentType = uc.getContentType();
int contentLength = uc.getContentLength();
InputStream isFile = uc.getInputStream();
BufferedInputStream in = new BufferedInputStream(isFile);
/*if( !fileSave.isFile() ){
strMsg = "파일이 존재하지 않습니다.";
out.println(strMsg);
}else{
strFileName = strFileName.replaceAll("\\[", "");
*/ strFileName = strFileName.replaceAll("\\]", "");
strFileName = strFileName.replaceAll(" ", "");
String strClient = request.getHeader("User-Agent");
if( strClient.indexOf("MSIE 5.5") != -1 ){
response.setHeader("Content-Type", "doesn/matter;");
response.setHeader("Content-Disposition", "filename=" + strFileName + ";");
}else{
response.setHeader("Content-Type", "application/octet-stream;");
response.setHeader("Content-Disposition", "attachment;filename="+strFileName + ";");
}
//isFile = new FileInputStream(fileSave);
osOut = response.getOutputStream();
int nSize = 0;
try{
byte[] _tmp = new byte[1024*2];
while ((nSize = isFile.read(buffer)) != -1) {
out.println(nSize);
osOut.write(buffer, 0, nSize);
osOut.flush();
}
}catch( Exception e ){
//e.printStackTrace();
}finally{
osOut.close();
isFile.close();
}
//}
}catch ( Exception e){
e.printStackTrace();
}
%>
'IT 세상 > 자바세상' 카테고리의 다른 글
TOMCAT5.5 bin bat/sh file (0) | 2011.05.31 |
---|---|
아파치 한글파일 다운로드 (0) | 2010.06.15 |
ant, eclipse jar 만들기 (0) | 2010.05.29 |
jsp filedown 소스 (0) | 2010.05.27 |
tag 내용(,구분자) 20개 제한 및 /score 뺴기 (0) | 2010.04.01 |