所有的图片都会上传到,upload文件目录下。这个参数也是可以变化的。
我们发出的请求::8080/UploadControl/dialog/stock.jsp?uploadpath=upload/purchase/&time=Sat%20Sep%2026%2020:51:29%20CST%202015
提交的方法是这样的:
<span style="font-size:18px;"> SmartUpload mySmartUpload = new SmartUpload();
mySmartUpload.initialize(pagecontext);
//mySmartUpload.initialize(config, request, response);
mySmartUpload.setMaxFileSize(20480 * 1024);
mySmartUpload.setAllowedFilesList("jpg,JPG,gif,GIF,png,PNG,jpeg,JPEG,bmp,BMP,tif,TIF,tiff,TIFF,swf,SWF,flv,FLV,doc,DOC,txt,TXT,xls,CLS,csv,CSV,ppt,PPT,zip,ZIP,rar,RAR");
mySmartUpload.upload();
File myFile = mySmartUpload.getFiles().getFile(0);
if (!myFile.isMissing()) {
if(FileName.equals(""))FileName=myFile.getFileName();
if(FileName.equals(""))
{
Date currTime = new Date();
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyyMMddhhmmssSSS", Locale.US);
FileName = new String((formatter2.format(currTime)).getBytes("iso-8859-1"));
}
String ext = myFile.getFileExt();
FileName = FileName + "." + ext;
myFile.saveAs(rpath + "/" + FileName,mySmartUpload.SE_AUTO);
}
;
} catch (Exception e) {
e.printStackTrace();
return "ERR:"+e.getMessage();
}
return FileName;</span>
提交路径为:
<span style="font-size:18px;"> if(sPath==null)sPath="/upload";
if(sPath.equals(""))sPath="/upload";
if(FileName==null)FileName="";
if(rootdir.equals(""))rootdir=pagecontext.getServletContext().getRealPath("/");
String rpath=rootdir+"/"+sPath;
java.io.File f = new java.io.File(rpath);
if(!f.exists())f.mkdirs();
rpath=f.getPath();</span>
总结:
在这个类中,我们发现写的真心的难看,但是,没有关系,我们只要会用了就可以了。
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-27832-4.html
正愁没理由进驻军事部署的