`
yangfuchao418
  • 浏览: 162041 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

jsp上传文件

阅读更多

Date d=new Date();
SimpleDateFormat aa = new SimpleDateFormat("yyyyMMdd-HHmmss");
SmartUpload fileup= new SmartUpload();
fileup.initialize(pageContext); // 上传初始化
fileup.setAllowedFilesList("jpg,gif,jpeg");//允许jpg,gif,jpeg文件。
fileup.setDeniedFilesList("exe,bat,jsp,htm,html,,");// 设定禁止上传的文件
fileup.upload();// 上传图片
String realurl="images/";
fileup.save(realurl);//保存到指定目录
//========================
String ext ="";
com.jspsmart.upload.File myFile = fileup.getFiles().getFile(0);
ext= myFile.getFileExt(); //取得后缀名
String filename=aa.format(d);
String myphoto=filename+"."+ext;//把时间作为文件名
String realpath=realurl+myphoto;
myFile.saveAs(realpath);

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics