⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 processdownload.java

📁 jsp中文件上传和下载
💻 JAVA
字号:
package com.buat;

import java.io.IOException;

import javax.servlet.ServletConfig;
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 ProcessDownload extends HttpServlet {
	private ServletConfig config = null;

	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		this.config = config;
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("gbk");

		SmartUpload down = new SmartUpload();

		String fileName = request.getParameter("fileName");

		down.initialize(config, request, response);
		down.setContentDisposition(null);

		// 获取文件路径
		StringBuffer path = new StringBuffer();
		path.append(this.getServletContext().getRealPath("/"));
		// String fileName =
		// GBK.to_GBK(request.getParameter("fileName").trim());

		path.append("document").append("\\");
		path.append(fileName);

		try {
			// 下载文件
			down.downloadFile(path.toString());
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (SmartUploadException e) {
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -