<%

// String Local_File ;


java.io.File f = new java.io.File ( Local_File ) ;


if ( f.isFile ( ) )

{

String fullname = GetNameFromFile ( Local_File ) + "." + GetExtFromFile ( Local_File ) ;


response.reset ( ) ;


String agent = request.getHeader ( "USER-AGENT" ) ;


if ( agent.indexOf ( "MSIE" ) != -1 )

{

fullname = java.net.URLEncoder.encode ( fullname , "UTF-8" ) ;

response.setContentType ( "application/x-download" ) ;

response.setHeader ( "Content-Disposition" , "attachment; filename=" + fullname ) ;

}

else // if ( agent.indexOf ( "Mozilla" ) != -1 )

{

fullname = MimeUtility.encodeText ( fullname , "UTF8" , "B" ) ;

response.setContentType ( "application/force-download" ) ;

response.addHeader ( "Content-Disposition" , "attachment; filename=\"" + fullname + "\"" ) ;

}


response.setHeader ( "Content-Transfer-Encoding" , "Binary;" ) ;

response.setHeader ( "Pragma" , "no-cache;" ) ;

response.setHeader ( "Expires" , "-1;" ) ;

response.setContentLength ( (int) f.length ( ) ) ;


int read = 0 ; byte b [ ] = new byte [ 32768 ] ;


java.io.BufferedInputStream fin = new java.io.BufferedInputStream ( new java.io.FileInputStream ( f ) ) ;

java.io.BufferedOutputStream outs = new java.io.BufferedOutputStream ( response.getOutputStream ( ) ) ;

while ( ( read = fin.read ( b ) ) != -1 ) outs.write ( b , 0 , read ) ; outs.flush ( ) ;

outs.close ( ) ;

fin.close ( ) ;

}

%>




'DB & SQL & web' 카테고리의 다른 글

[jsp] 한글 체크.  (0) 2013.07.25
[jsp] 이미지 업로드  (0) 2013.07.12
[jsp] 메일 보내기 (파일첨부)  (0) 2013.07.12
[jsp] 메일 보내기  (0) 2013.07.12
Apache James 설치 & PostgreSQL  (0) 2013.06.28