首页>代码>java servlet通过SmartUpload开发文件批量上传、批量下载源码分享>/fileBatchWithSmart/src/org/shengke/servlet/SmartDownloadServlet.java
package org.shengke.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.jspsmart.upload.SmartUpload; import com.jspsmart.upload.SmartUploadException; /** * 文件单一下载 */ public class SmartDownloadServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request,response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String filename = request.getParameter("filename"); System.out.println("filename:"+filename); //单一文件下载没啥可说的 SmartUpload su = new SmartUpload(); su.initialize(getServletConfig(), request, response); //设置响应类型 su.setContentDisposition(null); try { su.downloadFile("/images/"+ filename); } catch (SmartUploadException e) { e.printStackTrace(); } } }