上传:
MyjspFormmf=(MyjspForm)form;//TODOAuto-generatedmethodstub
FormFilefname=mf.getFname();
byte[]fn=fname.getFileData();
OutputStreamout=newFileOutputStream("D:"+fname.getFileName());
Datedate=newDate();
Stringtitle=fname.getFileName();
Stringurl="d:"+fname.getFileName();
Uploadul=newUpload();
ul.setDate(date);
ul.setTitle(title);
ul.setUrl(url);
UploadDAOuld=newUploadDAO();
uld.save(ul);
out.write(fn);
out.close();
下载:
DownloadFormdownloadForm=(DownloadForm)form;
Stringfname=request.getParameter("furl");
FileInputStreamfi=newFileInputStream(fname);
byte[]bt=newbyte[fi.available()];
fi.read(bt);
//设置文件是下载还是打开以及打开的方式msdownload表示下载;设置字湖集,//主要是解决文件中的中文信息
response.setContentType("application/msdownload;charset=gbk");
//文件下载后的默认保存名及打开方式
StringcontentDisposition="attachment;filename="+"java.txt";
response.setHeader("Content-Disposition",contentDisposition);
//设置下载长度
response.setContentLength(bt.length);
ServletOutputStreamsos=response.getOutputStream();
sos.write(bt);
returnnull;