论坛首页 入门讨论版 EXT

ext 上传组件Ext.ux.UploadDialog 的问题!

浏览 1610 次
该帖已经被评为新手帖
作者 正文
最后更新时间:2008-03-11 关键字: 疑惑
今天用ext 解决文件上传的问题,2.0好像没有上传组件了。。
找来找去,看到了Ext.ux.UploadDialog。
没有找到JSP 后台处理的例子。
看了下帮助,The files in the queue are posted one at a time, the file field name is 'file'.
没有理解,file 怎么用后台获得值。
我用JSP 试了下,一直都是null。。
    不知道谁能给指点下, 关于Ext.ux.UploadDialog +JSP 的例子。。
   
最后更新时间:2008-03-12
Ext.ux是1.0里面的包么?
好像在2.0l里面没有看到
   
0 请登录后投票
最后更新时间:2008-03-24
我用的是servlet 也遇到同样的问题,好像EXt没有提交一样:

// JScript File
Ext.onReady(function() {
Ext.QuickTips.init();  
  var btnShow = new Ext.Button({
        text:'上传文件',
        listeners:{
            click:function(btnThis,eventobj){
               dialog = new Ext.ux.UploadDialog.Dialog({
                  url: 'fileupload',
                  reset_on_hide: false,
                  allow_close_on_upload: true,
                  upload_autostart: true
                });
                dialog.show('show-button');
            }
        }
  });
   btnShow.render("show-dialog-btn");
}); //Ext.onReady




servlet:


package com.hiber;

import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
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:\\uploadtest\\"; // 用于存放上传文件的目录

	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中提取文件名:
					String extfile = fileName.substring(fileName.indexOf("."));
					
					Timestamp now = new Timestamp((new java.util.Date())
							.getTime());

	                 SimpleDateFormat   fmt   =   new   SimpleDateFormat("yyyyMMddHHmmssSSS");   
	                String  pfileName=   fmt.format(now).toString().trim();   
					System.out.println(uploadPath+pfileName+extfile);
					fi.write(new File(uploadPath + pfileName + extfile));
				}
			}
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().print("{'success':true,'message':'上传成功'}");
			// 跳转到上传成功提示页面
		} catch (Exception e) {
			e.printStackTrace();
			response.getWriter().print("{'success':flase,'message':'失败'}");
			// 可以跳转出错页面
		}

	}
}
   
0 请登录后投票
最后更新时间:2008-03-24
这样是可以正常提交的:


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body>
<form action="fileupload" method="post" enctype="multipart/form-data" name="form1">
  <input name="thisfile" type="file" id="thisfile">
  <input name="user" type="text" id="user" size="10">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
   
0 请登录后投票
最后更新时间:2008-04-09
我也出现楼主的情况,List fileItems = fu.parseRequest(request);得到的是个null,难道是是没有提交,各位有没有什么解决办法。
   
0 请登录后投票
最后更新时间:2008-05-27
我用的Struts的FormFile实现了上传文件的保存
      dialog = new Ext.ux.UploadDialog.Dialog({
        url: 'upload.do?method=upload',
        reset_on_hide: false,
        allow_close_on_upload: true,
        upload_autostart: true,
        post_var_name: 'upload'
      });

后台实现,其中BaseForm继承了LazyValidatorForm
		BaseForm myform = (BaseForm)form;		

		FormFile file = (FormFile)myform.get("upload");
		String fileName = file.getFileName();
		
        InputStream is = file.getInputStream();
        long file_size = file.getFileSize();
        int MAX_BUFFER_LENGTH = 1024;
        
		try {
			OutputStream bos = new FileOutputStream("D:\\temp\\"+fileName);
	        int bytesRead = 0;
	        byte[] buffer = new byte[MAX_BUFFER_LENGTH];
	        while ((bytesRead = is.read(buffer, 0, MAX_BUFFER_LENGTH)) != -1) {
	            bos.write(buffer, 0, bytesRead);
	            bos.flush();
	        }
	        bos.close();
		}catch (FileNotFoundException e) {
			throw new DataNotExistException(fileName + " 文件未找到!");
		} catch (IOException e) {
			throw new RuntimeException("存储文件失败!");
		} finally {
			
		}

这里关键是"post_var_name: 'upload'",指定上传文件存放的表单属性名
   
0 请登录后投票
最后更新时间:2008-06-18
kaki 写道
我用的是servlet 也遇到同样的问题,好像EXt没有提交一样:

// JScript File
Ext.onReady(function() {
Ext.QuickTips.init();  
  var btnShow = new Ext.Button({
        text:'上传文件',
        listeners:{
            click:function(btnThis,eventobj){
               dialog = new Ext.ux.UploadDialog.Dialog({
                  url: 'fileupload',
                  reset_on_hide: false,
                  allow_close_on_upload: true,
                  upload_autostart: true
                });
                dialog.show('show-button');
            }
        }
  });
   btnShow.render("show-dialog-btn");
}); //Ext.onReady




servlet:


package com.hiber;

import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
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:\\uploadtest\\"; // 用于存放上传文件的目录

	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中提取文件名:
					String extfile = fileName.substring(fileName.indexOf("."));
					
					Timestamp now = new Timestamp((new java.util.Date())
							.getTime());

	                 SimpleDateFormat   fmt   =   new   SimpleDateFormat("yyyyMMddHHmmssSSS");   
	                String  pfileName=   fmt.format(now).toString().trim();   
					System.out.println(uploadPath+pfileName+extfile);
					fi.write(new File(uploadPath + pfileName + extfile));
				}
			}
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().print("{'success':true,'message':'上传成功'}");
			// 跳转到上传成功提示页面
		} catch (Exception e) {
			e.printStackTrace();
			response.getWriter().print("{'success':flase,'message':'失败'}");
			// 可以跳转出错页面
		}

	}
}





我也同样用上面的代码,为什么好像没有到后台。
   
0 请登录后投票
最后更新时间:2008-06-18
wangtong40 写道
kaki 写道
我用的是servlet 也遇到同样的问题,好像EXt没有提交一样:

// JScript File
Ext.onReady(function() {
Ext.QuickTips.init();  
  var btnShow = new Ext.Button({
        text:'上传文件',
        listeners:{
            click:function(btnThis,eventobj){
               dialog = new Ext.ux.UploadDialog.Dialog({
                  url: 'fileupload',
                  reset_on_hide: false,
                  allow_close_on_upload: true,
                  upload_autostart: true
                });
                dialog.show('show-button');
            }
        }
  });
   btnShow.render("show-dialog-btn");
}); //Ext.onReady




servlet:


package com.hiber;

import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
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:\\uploadtest\\"; // 用于存放上传文件的目录

	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中提取文件名:
					String extfile = fileName.substring(fileName.indexOf("."));
					
					Timestamp now = new Timestamp((new java.util.Date())
							.getTime());

	                 SimpleDateFormat   fmt   =   new   SimpleDateFormat("yyyyMMddHHmmssSSS");   
	                String  pfileName=   fmt.format(now).toString().trim();   
					System.out.println(uploadPath+pfileName+extfile);
					fi.write(new File(uploadPath + pfileName + extfile));
				}
			}
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().print("{'success':true,'message':'上传成功'}");
			// 跳转到上传成功提示页面
		} catch (Exception e) {
			e.printStackTrace();
			response.getWriter().print("{'success':flase,'message':'失败'}");
			// 可以跳转出错页面
		}

	}
}





我也同样用上面的代码,为什么好像没有到后台。

麻烦问一下:Ext.ux.UploadDialog.Dialog是针对Ext2.0 的还是Ext1.0的:
我同样使用的是上面的代码,但是什么原因导致的没有后台相应呢?
   
0 请登录后投票
最后更新时间:2008-07-23
我用servlet也遇到了同样的问题。怎么没有高人来解答呢
   
0 请登录后投票
最后更新时间:2008-08-08
T-T 我也是使用相同的东东,也是提交不了
   
0 请登录后投票
论坛首页 入门讨论版 EXT

跳转论坛:
JavaEye推荐