使用servlet完成单文件下载和批量文件下载。批量下载的原理是先将文件打包成zip , 然后再下载。
之前也转载过一篇文件下载的博客,地址:http://blog.csdn.net/ch717828/article/details/42809999
这篇的demo要更简单一些,需要深入了解更参数含义的可以看第一篇博客
单文件下载:
<a href="servlet/SmartDownLoadFile?filename=gui.jpg">附件</a>
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SmartDownLoadFile extends HttpServlet {
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the serv