<%
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...
-
Trước tiên tạo một class ColorTable.java import java.awt.Color; import javax.swing.JTable; import javax.swing.table.*; public class Col...
-
References: https://www.youtube.com/watch?v=EH6h7WA7sDw Class Item class Item { private $_weight; private $_value; public functi...
-
Xem log của một file nào đó: git log --follow ...
please you share to me about full code
ReplyDelete