<%@page import="org.apache.velocity.tools.view.servlet.WebappLoader"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.OutputStream"%>
<%@page import="java.io.InputStream"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
<%
String str = request.getParameter("path");
if(str == null || "".equals(str)){
return;
}
String path = request.getRealPath(str);
File file = new File(path);
if (!file.exists() || file.isDirectory()) {
return;
}
InputStream input = null;
OutputStream output = null;
try{
output = response.getOutputStream();
input = new FileInputStream(file);
response.setHeader("Content-disposition","attachment;filename="+str.substring(str.lastIndexOf("/")+1));
byte[] buf = new byte[1024];
int i = 0;
while((i=input.read(buf)) != -1){
output.write(buf,0,i);
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(output != null){
output.flush();
output.close();
}
if(input != null){
input.close();
}
}catch(Exception e){
e.printStackTrace();
}
out.clear();
out = pageContext.pushBody();
}
%>
</head>
</html>
down_file.jsp 文件下载页面
最新推荐文章于 2022-08-19 17:06:44 发布