processdownload.java
来自「jsp中文件上传和下载」· Java 代码 · 共 59 行
JAVA
59 行
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 + =
减小字号Ctrl + -
显示快捷键?