日期:2014-05-19 浏览次数:20657 次
try
{
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String name=request.getParameter("name");
String fname=request.getParameter("filename");
System.out.println(name+"文件名");
System.out.println(fname+"文件夹");
String webpath=request.getSession().getServletContext().getRealPath("")+"/"+"manage_file"+"/"+"public_space/";
String savePath=webpath+fname;
response.setContentType("application/x-download");
String filenamedownload = savePath + "/" + name;
String filenamedisplay = name;
filenamedisplay = URLEncoder.encode(filenamedisplay, "UTF-8");
response.setHeader("Content-Disposition", "attachment;filename="+ filenamedisplay);
try {
OutputStream os = response.getOutputStream();
FileInputStream fis = new FileInputStream(filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while ((i = fis.read(b)) > 0) {
os.write(b, 0, i);
}
fis.close();
os.flush();
os.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
catch(Exception e)
{
e.printStackTrace();
}