String filename = request.getParameter("filename");
ServletContext servletContext = this.getServletContext();
String realPath = servletContext.getRealPath("/img/" + filename);
FileInputStream fis = new FileInputStream(realPath);
String mimeType = servletContext.getMimeType(filename);
response.setHeader("content-type",mimeType);
String agent = request.getHeader("user-agent");
filename=DownLoadUtils2.getFileName(agent,filename);
response.setHeader("content-disposition","attachment,filename="+filename);
ServletOutputStream sos = response.getOutputStream();
byte[] buff = new byte[1024 * 8];
int len = 0;
while ((len = fis.read(buff))!=-1){
sos.write(buff,0,len);
}
fis.close();