[java]
package com
import java
import java
import java
import java
import
import javax
import javax
import javax
import javax
public class DownloadServlet extends HttpServlet {
public void doGet(HttpServletRequest request
throws ServletException
String filename = request
filename = new String(filename
System
//找到該文件所在的文件夾位置
//String savepath = this
String savepath = this
File f = new File(savepath+
if(!f
request
request
}
response
FileInputStream in = new FileInputStream(f);
byte[] buf = new byte[
int len=
OutputStream out = response
while((len=in
out
}
in
}
public String getFileSavePath(String filename){
int dir
int dir
String savepath = this
return savepath;
}
public String getRealName(String filename){
String realName = filename
return realName;
}
public void doPost(HttpServletRequest request
throws ServletException
doGet(request
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26051.html