前台js:

form:

Ext.define("GS.base.BasicImportForm",{
    extend:"Ext.form.Panel",
    alias:"widget.basicImportForm",
    frame:true,
    tbar:[],
    layout:{
        type:'table'
    },
    items:[{
           xtype:'fileuploadfield',
           fieldLabel:'文件信息',
           name:'file',
           labelWidth:60,
           width:350,
           allowbBlank:false,
           msgTarget:'side',
           buttonText:'选择文件'
         }
    ]
});

controller:

"baseModelGrid button[ref=doc_upload]":{
                click:function(){
                 var win =Ext.create('Ext.Window', {
                        height: 250,
                        width: 500,
                        layout: 'fit',
                        closeAction: 'hide',
                        maximizable: true,          //是否可以最大化
  
                     minimizable: true,          //是否可以最小化          
                                                                      
                        resizable: true,  //是否可以改变窗口大小        
                        modal :true,//为真 当显示时,制作窗口模板并且掩饰他背后的一切
                        tbar:[
                              {xtype:"button",text:"上传",ref:"docupload",iconCls:"up",
                                  listeners:{
                                    'click':function(bt,e,eOpts){
                                        var basicImportForm = bt.up("window").down("basicImportForm");
                                        var formObj = basicImportForm.getForm();
                                        var file=formObj.findField("file");
                                        var str = file.getValue();
                                        var filename=str;
                                        str = str.substr(str.indexOf('.'),str.length - 1);
                                        if("" == str || str==".exe") {
                                            Ext.MessageBox.alert("提示","文件不能为空或者以.exe结尾!");
                                            return;
                                        };
                                        if(!Ext.isEmpty(file.getValue())){
                                            Ext.MessageBox.buttonText = {
                                                      ok     : "确定",
                                                      cancel : "取消",
                                                      yes    : "是",
                                                      no     : "否"
                                            };
                                            Ext.MessageBox.confirm("系统提示","确定是否上传?",function(btn,txt){
                                                if(btn == "yes"){
                                                    basicImportForm.submit({
                                                        url:'loadAction!upload.action',
                                                        params:{fileName:filename},                                    
                                                        waitMsg:'正在上传....',
                                                         success:function(form,action){
                                                            var resObj = action.result;
                                                            if (resObj.success) {
                                                                Ext.Msg.alert("提示","上传成功");
                                                                win.hide();
                                                            }else{
                                                                Ext.Msg.alert("提示","上传失败");
                                                            }
                                                        },
                                                        failure:function(form, action){
                                                            Ext.Msg.alert("提示","上传失败");
                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    }
                                }
                              }
                           ],
                        items: [{  xtype: "basicImportForm"}]
                    }).show();
                }
            }

显示页面:

'-',{xtype:'button',text:'上传',ref:'doc_upload'}

java代码:

public class LoadAction extends BaseAction {
    /**
     * 序列号
     */
    private static final long serialVersionUID = 1L;
    //这个是用来写运行结果的信息的
    private  String msg;
    //来返回信息给前台的因为这里继承了baseaction直接用了towrite没有用到,否则可以通过它进行信息的返回
    private String contentType;
    //这个file是从extjs的form中的对应的xtype=fileupload name=file来的,名字一定要相对应,不然无法获得文件
    private File file;
    //filename是从前台传过来的,也可以通过request得到然后自己拼接
    private String fileName;

public void upload() throws Exception {
        //文件上传保存的位置
        String realPath = "E:\\" + fileName;
        if (file.isFile()) {
            //定义并初始化io流的读写操作
            BufferedInputStream bis = new BufferedInputStream(
                    new FileInputStream(file));
            BufferedOutputStream bos = null;
            try {
                bos = new BufferedOutputStream(new FileOutputStream(realPath));// 为以防万一,写文件的路径尽量写成正双斜杠的
                // 从源文件中取数据,写到目标文件中
                byte[] buff = new byte[8192];
                for (int len = -1; (len = bis.read(buff)) != -1;) {
                    bos.write(buff, 0, len);
                }
                bos.flush();
            } catch (IOException ie) {
                ie.printStackTrace();
                toWrite(jsonBuilder.returnFailureJson("'文件上传失败'"));
            } finally {
                if (bis != null) {
                    try {
                        bis.close();
                    } catch (IOException ie) {
                        ie.printStackTrace();
                    }
                }
                if (bos != null) {
                    try {
                        bos.close();
                    } catch (IOException ie) {
                        ie.printStackTrace();
                    }
                }
            
            }
        }
        toWrite(jsonBuilder.returnSuccessJson("'文件上传成功'"));
                
    }

public String getFileName() {
        return fileName;
    }

public void setFileName(String fileName) {
        this.fileName = fileName;
    }

// since we are using <s:file name="upload" .../> the file name will be
    // obtained through getter/setter of <file-tag-name>FileName
    public String getUploadFileName() {
        return fileName;
    }

public void setUploadFileName(String fileName) {
        this.fileName = fileName;
    }

// since we are using <s:file name="upload" ... /> the content type will be
    // obtained through getter/setter of <file-tag-name>ContentType
    public String getUploadContentType() {
        return contentType;
    }

public void setUploadContentType(String contentType) {
        this.contentType = contentType;
    }

// since we are using <s:file name="upload" ... /> the File itself will be
    // obtained through getter/setter of <file-tag-name>
    public File getUpload() {
        return file;
    }

public void setUpload(File file) {
        this.file = file;
    }

public String getMsg() {
        return msg;
    }

public void setMsg(String msg) {
        this.msg = msg;
    }

public String getContentType() {
        return contentType;
    }

public void setContentType(String contentType) {
        this.contentType = contentType;
    }

public File getFile() {
        return file;
    }

public void setFile(File file) {
        this.file = file;
    }  
       
   
    
}

extjs采用fileupload进行文件上传后台实现的更多相关文章

  1. zt对于C#中的FileUpload解决文件上传大小限制的问题设置

    对于C#中的FileUpload解决文件上传大小限制的问题设置 您可能没意识到,但对于可以使用该技术上载的文件的大小存在限制.默认情况下,使用 FileUpload 控件上载到服务器的文件最大为 4M ...

  2. 使用fileupload实现文件上传

    一. fileupload组件工作原理 先来张图片, 帮助大家理解 fileupload核心API 1. DiskFileItemFactory构造器1) DiskFileItemFactory() ...

  3. SpringMvc 文件上传后台处理

    springMVC后台参数是通过MultipartFile类来转化Request的文件上传,但需要apache下fileupload的jar包做支持. 在springMVC的dispatcher-co ...

  4. zk FileUpload(文件上传)

    <button label="上传 Image" upload="true,maxsize=1073741824"> <attribute n ...

  5. asp.net web常用控件FileUpload(文件上传控件)

    FileUpload控件的主要中能:向指定目录上传文件,该控件包括一个文本框和一个浏览按钮. 常用的属性:FileBytes,FileContent.FileName.HasFile.PostedFi ...

  6. Apache Commons fileUpload实现文件上传之一

      需要两个jar包: commons-fileupload.jar Commons IO的jar包(本文使用commons-io-2.4.jar) 利用Servlet来实现文件上传. package ...

  7. Spring MVC使用commons fileupload实现文件上传功能

    通过Maven建立Spring MVC项目,引入了Spring相关jar依赖. 1.为了使用commons fileupload组件,需要在pom.xml中添加依赖: <properties&g ...

  8. Apache Commons FileUpload 实现文件上传

    Commons FileUpload简介 Apache Commons是一个专注于可重用Java组件开发的 Apache 项目.Apache Commons项目由三个部分组成: 1.Commons P ...

  9. 实用ExtJS教程100例-009:ExtJS Form无刷新文件上传

    文件上传在Web程序开发中必不可少,ExtJS Form中有一个filefield字段,用来选择文件并上传.今天我们来演示一下如何通过filefield实现ExtJS Form无刷新的文件上传. 首先 ...

随机推荐

  1. jquery easyui-linkButton获取和设置按钮text并且解决火狐不支持innerText的方法

    <a href="javascript:test" id="btn" class="easyui-linkbutton" iconCl ...

  2. Spring REST实践之Documenting REST Services

    Swagger基本介绍 Swagger是创建交互式REST API文档的规范和框架,它能自动同步REST服务的任何变化,同时为生成API客户端代码提供了一套工具和SDK生成器.Swagger规范由两种 ...

  3. (剑指Offer)面试题22:栈的压入、弹出序列

    题目: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等. 例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序 ...

  4. 快速界面:QML。

    PyQt, QML,Qt Quick. QML: QML可以在脚本里创建图形对象,并且支持各种图形特效,以及状态机等,同时又能跟Qt写的C++代码进行方便的交互,使用起来非常方便. 功能性不能,此篇博 ...

  5. js 解决原型问题的方案 : 构造器和原型的组合

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. 你可能不知道的Linux/GNU bash sort多列排序功能

    (转载请注明原创于潘多拉盒子) Linux man pages的缺点就是,如果你不会用某个命令,那么看完了多半还是不会.原因是,没有例子!比较囧吧? sort是提供了多列排序的功能的.通过-k选项,可 ...

  7. 双网卡绑定-bond0

    网卡绑定就是多张网卡逻辑上作为一张网卡用.可分为,负载均衡绑定和冗余绑定两种. 1.编辑虚拟网络接口配置文件 [root@test~]# more /etc/sysconfig/network-scr ...

  8. 试读《JavaScript语言精髓与编程实践》

    有幸看到iteye的活动,有幸读到<JavaScript语言精髓与编程实践_第2版>的试读版本,希望更有幸能完整的读到此书. 说来读这本书的冲动,来得很诡异,写一篇读后感,赢一本书,其实奖 ...

  9. 使用jQuery Mobile和Phone Gap开发Android应用程序

    经过了一段时间的学习,初步了解了该如何使用jQuery Mobile和 Phone Gap来开发一个Android应用程序,也想把这些东西介绍给大家. 1. 软件准备 要进行android app的开 ...

  10. Cocos2d-x--开发参考资料

    1.CocoStudio使用指南 所用版本:CocoStudio v3.0.0 Cocos2d-x1.5b 自己网上查找并整理的一些资料,留下做个纪念,也希望对有需要的人有点帮助 链接地址:http: ...