String fileName = request.getParameter("fileName");
String folderPath = this.getServlet().getServletContext().getRealPath("/download");
String fileRealPath = folderPath +"/"+ fileName;
try {
response.setContentType("bin");
response.addHeader("Content-Disposition", "attachment;filename=/""+URLEncoder.encode(fileName, "utf-8")+"/"");
InputStream is = new FileInputStream(fileRealPath);
OutputStream os = response.getOutputStream();
byte[] b = new byte[1024];
int len = 0;
while((len = is.read(b))>0){
os.write(b,0,len);
}
is.close();
os.flush();
os.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
struts下载
最新推荐文章于 2023-02-09 00:09:46 发布