`
firelife
  • 浏览: 31372 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

Ext.ux.dialog common-fileupload 整合[收]

    博客分类:
  • java
阅读更多
Ext.onReady(function() { 
var dialog = new Ext.ux.UploadDialog.Dialog(null, 
{
autoCreate : true,
closable : true,
collapsible : false, 
draggable : true,
minWidth : 500, 
minHeight : 200,
width : 400, 
height : 350,
proxyDrag : true, 
resizable : true, 
//permitted_extensions : ['JPG', 'jpg', 'jpeg', 'JPEG', 'GIF',  'gif','doc','xls'],
constraintoviewport : true,
title : '文件上传的例子', 
url : '/NewSMS/fileupload', 
reset_on_hide : false, 
allow_close_on_upload : true
}); 
dialog.show('my-dlg');
});


package com.hiber;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;

public class Upload extends HttpServlet {
    /**
     * 
     */
    private static final long serialVersionUID = 7440302204266787092L;

    String uploadPath = "d:\\"; // 用于存放上传文件的目录

    String tempPath = "d:\\tmp\\"; // 用于存放临时文件的目录
    
    public Upload(){
         super();
         System.out.println("文件上传启动");
    }

    public void destroy() {
           super.destroy(); // Just puts "destroy" string in log
           // Put your code here
        }

    public void init() throws ServletException {
        System.out.println("文件上传初始化");
        }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        try {
            System.out.println("开始进行文件上传");
            DiskFileUpload fu = new DiskFileUpload();
            fu.setSizeMax(4194304); // 设置最大文件尺寸,这里是4MB
            fu.setSizeThreshold(4096); // 设置缓冲区大小,这里是4kb
            fu.setRepositoryPath(tempPath); // 设置临时目录
            List fileItems = fu.parseRequest(request); // 得到所有的文件:
            Iterator i = fileItems.iterator();
            // 依次处理每一个文件:
            while (i.hasNext()) {
                FileItem fi = (FileItem) i.next();
                String fileName = fi.getName();// 获得文件名,这个文件名包括路径:
                if (fileName != null) {
                    // 在这里可以记录用户和文件信息
                    // 此处应该定义一个接口(CallBack),用于处理后事。
                    // 写入文件a.txt,你也可以从fileName中提取文件名:
                    fi.write(new File(uploadPath + "a.txt"));
                }
            }
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().print("{success:true,msg:'成功'}"); 
            // 跳转到上传成功提示页面
        } catch (Exception e) {
            response.getWriter().print("{success:flase,msg:'失败'}"); 
            // 可以跳转出错页面
        }

    }
}
分享到:
评论
1 楼 BlackSwallow 2008-09-28  
List fileItems = fu.parseRequest(request); //
这里fileItems 得到的是空!怎么回事?

相关推荐

Global site tag (gtag.js) - Google Analytics