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();
}
{
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();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货