downfile.jsp
显示下载
您已经上传的文件:
String path=request.getSession().getServletContext().getRealPath("/");
File file1=new File(path,"//upload");
String str[]=file1.list();
for(int i=0;i
String ss=str[i];
out.println("
"+ss+"下载");
}
%>
downfile1.jsp
Document : Downfile1
Created on : -4-22, 18:18:37
Author : Administrator
--%>
try{
String str=request.getParameter("name1");
str=new String(str.getBytes("ISO-8859-1"),"gb2312");
File fileLoad=new File("F://大二课程//JSP//JSP程序设计与项目实训教程教学资料//代码//ch10//PIMS//build//web//upload",str);
response.reset();
OutputStream o=response.getOutputStream();
BufferedOutputStream bos=new BufferedOutputStream(o);
byte b[]=new byte[5000];
response.setHeader("Content-disposition","attachment;filename="+new String(str.getBytes("gb2312"),"ISO-8859-1"));
response.setContentType("application/x-tar");
long fileLength=fileLoad.length();
String length=String.valueOf(fileLength);
response.setHeader("Content_Length",length);
FileInputStream in=new FileInputStream(fileLoad);
int n=0;
while((n=in.read(b))!=-1)
{
bos.write(b,0,n);
}
bos.close();
}catch(Exception e){
out.println(e);
}
response.reset();
%>
..
e.getMessage()
Document : Downfile
Created on : -4-22, 17:55:43
Author : Administrator
--%>
显示下载
您已经上传的文件:
String path=request.getSession().getServletContext().getRealPath("/");
File file1=new File(path,"//upload");
String str[]=file1.list();
for(int i=0;i
String ss=str[i];
out.println("
"+ss+"下载");
}
%>