<%
String fileName = (String)request.getParameter("fileName");
String path = request.getRealPath("/")+"/WEB-INF/fileDownload/";
File file = new File(path+fileName);
System.out.println("file path:"+path+fileName);
System.out.println("Name:"+file.getName());
FileInputStream fis = new FileInputStream(file);
FileTypeMap ftm = new MimetypesFileTypeMap();
response.setContentType(ftm.getContentType(path+fileName));
response.setHeader("Content-Disposition",
"attachment; filename=" + file.getName());
int iRead;
while((iRead=fis.read())!=-1){
response.getOutputStream().write(iRead);
}
response.getOutputStream().flush();
System.out.println("Download complete");
%>
5/29/2010
Code download file trong JSP
Code được sử dụng để tạo trang download, khi người sử dụng click download thi sẽ tự động bung của sổ save file của trình duyệt.
Subscribe to:
Post Comments (Atom)
The 0/1 Knapsack Problem - Dynamic Programming
References: https://www.youtube.com/watch?v=EH6h7WA7sDw Class Item class Item { private $_weight; private $_value; public functi...
-
$my_array = array(2, "a", null, 2.5, NULL, 0, "", 8, -1,array()); class ArrayFilter { public static function not_emp...
-
Hôm nay dùng SVN mới biết là mặc định NetBeans dùng 4 spaces thay vì 1 tab khi chọn chuột phải format, làm update code từ SVN về đỏ lòm, mặc...
-
References: https://www.youtube.com/watch?v=EH6h7WA7sDw Class Item class Item { private $_weight; private $_value; public functi...
please you share to me about full code
ReplyDelete