首页>代码>基于servlet和jsp的文件上传下载小例子>/upload/src/com/servlet/DownloadServlet.java
package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;

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 DownloadServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public DownloadServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String fileName=new String(request.getParameter("file").getBytes("ISO-8859-1"),"GBK");
		System.out.println(fileName);
		SmartUpload su=new SmartUpload();
		su.initialize(this.getServletConfig(),request,response);
		su.setContentDisposition(null);
		try {
			su.downloadFile("/upfile/"+fileName);
		} catch (SmartUploadException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
最近下载更多
jameshkj  LV8 2023年5月18日
lironggang  LV38 2022年11月20日
15185836794  LV2 2021年11月8日
chenynhz  LV2 2021年9月16日
1126055836  LV13 2021年8月20日
isMrQt  LV1 2021年7月15日
15630419308  LV2 2021年5月16日
keeeww  LV1 2020年11月20日
小仙女本仙haha  LV8 2020年6月20日
lyd19931203  LV21 2020年6月16日
最近浏览更多
asddwh  LV12 2023年12月29日
1WQAQW1  LV2 2023年6月8日
jameshkj  LV8 2023年5月18日
qiuqiuqiu111  LV4 2022年11月29日
lironggang  LV38 2022年11月20日
109284656  LV1 2022年10月26日
yymmdm  LV6 2022年9月5日
kenway  LV2 2022年8月28日
zzzsy1  LV3 2022年7月28日
ming_123_9715  LV23 2022年7月19日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友