栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Struts2+uploadify多文件上传实例

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Struts2+uploadify多文件上传实例

本文实例为大家分享了Struts2+uploadify多文件上传的具体代码,供大家参考,具体内容如下

首先我这里使用的是  Jquery  Uploadify3.2的版本

导入相关的CSS  JS  



接下来是  上传的 JSP 页面代码



  

上传 取消上传

这里是最关键的JS 代码,有注释

$(function(){
  $("#img_file").uploadify({
   auto:false,//是否自动上传
  height: 30, 
    buttonText:'选择图片',
   cancelImage:'<%=basePath%>img/uploadify/uploadify-cancel.png',
  swf : '<%=basePath %>js/uploadify/uploadify.swf',
  // expressInstall:'js/uploadify/expressInstall.swf',
  uploader : '<%=basePath%>json/fileUploadAction.action', //后台处理上传文件的action 
  width : 120 ,
    'multi': true, //设置为true将允许多文件上传 
    'filesSelected': '4',
    queueID:'uploadfileQueue',
  fileObjName:'img_file', //与后台Action中file属性一样
     
    fileTypeDesc:'上传文件支持的文件格式:jpg,jpge,gif,png',
 fileTypeExts:'*.jpg;*.jpge;*.gif;*.png',/
@Controller
@Scope("prototype")
public class FileUploadAction extends baseAction {
 private File img_file;
 private String img_fileContentType;//格式同上"fileName"+ContentType 
 private String img_fileFileName;//格式同上"fileName"+FileName 
 private String savePath;//文件上传后保存的路径
 private Map dataMap = new HashMap();
 
 @Override
 
 public String execute() throws Exception{
 
 System.out.println("savePath"+getSavePath());
 
 File dir=new File(getSavePath()); 
 System.out.println(dir.getAbsolutePath());
 
 //判断是否存在路径
   if(!dir.exists()){ 
    dir.mkdirs(); 
   } 
   
   //当前上传的文件
   File file=getImg_file();
   //获得后缀
   String ext =FileUtil.getExtensionName(getImg_fileFileName()); 
   String newFileName = UUID.randomUUID()+ext;
    FileOutputStream fos=new FileOutputStream(getSavePath()+"//"+newFileName); 
    FileInputStream fis=new FileInputStream(getImg_file()); 
    byte []buffers=new byte[1024]; 
    int len=0; 
    while((len=fis.read(buffers))!=-1){ 
     fos.write(buffers,0,len); 
    } 
 
    fos.close();
    fis.close();
 
   // String uploadFileName = getImg_fileFileName();
    dataMap.put("filename",newFileName);
 
 return SUCCESS;
 }

 
  E:/Tomcat6.0/webapps/uploads 
  
 dataMap
 

配置完以上的基本就OK了。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/140129.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号