ExtJS:文件上传实例

var ext_dateFormat = 'Y-m-d H:i:s';
var dateFormat = 'yyyy-MM-dd HH:mm:ss';
var date = new Date();
Ext.onReady(function() {
var fifp =Ext.create('Ext.form.Panel', {
renderTo: 'fi-form',
width: 500,
frame: true,
title: '文件上传',
bodyPadding: '10 10 0', defaults: {
anchor: '100%',
allowBlank: false,
msgTarget: 'side',
labelWidth: 80
},
items: [{
xtype: 'textfield',
fieldLabel: '样品编号',
id:'finfo',
name:'finfo'
},{
xtype: 'container',
layout: 'hbox',
items: [{
xtype: 'textfield',
fieldLabel: '当前经度',
id:'flongitude',
name:'flongitude',
msgTarget: 'side',
allowBlank: false,
labelWidth: 80
}, {
xtype: 'textfield',
fieldLabel: '当前纬度',
id:'flatitude',
name:'flatitude',
msgTarget: 'side',
allowBlank: false,
labelWidth: 80
}]
},{
xtype : 'textfield',
fieldLabel : '上传时间',
id : 'ftime',
name : 'ftime',
// yyyy-MM-dd HH:mm:ss
value : Ext.Date.format(new Date(date.getFullYear(),date.getMonth(),date.getDate(),
date.getHours(),date.getMinutes(),date.getSeconds()), ext_dateFormat),
listeners : {
'focus' : function() {
WdatePicker({
dateFmt : dateFormat
});
}
}
},{
xtype: 'filefield',
id: 'fiupload',
emptyText: '请点击右边按钮选择文件!',
fieldLabel: '选择文件',
name: 'fiupload',
buttonText: '浏览文件',
buttonConfig: {
iconCls: 'upload-icon'
}
}], buttons: [{
text: '保存文件',
handler: function(){
var fiform = this.up('form').getForm();
if(fiform.isValid()){
fiform.submit({
type : 'ajax',
url: 'files/addData.action',
method : "POST",
waitMsg: ' 正在上传,请稍候...',
success: function(form, action) {
Ext.Msg.alert('Success','文件上传成功!');
},
failure:function(form, action)
{
Ext.Msg.alert("Failure","文件上传失败");
}
});
}
}
},{
text: '重新上传',
handler: function() {
this.up('form').getForm().reset();
}
}]
}); });

后台处理核心类方法:

	private static final int BUFFER_SIZE = 16 * 1024;

	public String addData() throws Exception {
Timestamp ts = new Timestamp(System.currentTimeMillis());
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");// 设置日期格式
ts = Timestamp.valueOf(this.ftime);
System.out.println(ts);
String nowtime = df.format(new Date());
System.out.println("uploadFileName = " + this.fiuploadFileName);
System.out.println("uploadContentType = " + this.fiuploadContentType);
System.out.println(nowtime);
// upload -- wapps 下面的文件夹,用来存放图片
String toSrc = ServletActionContext.getServletContext().getRealPath(
"upload")
+ "/" + nowtime + getFileExp(this.fiuploadFileName); // 使用時間戳作為文件名
String toFilename = nowtime + getFileExp(this.fiuploadFileName);
String toSrcPath = "./upload/" + toFilename;
String toinfo = this.finfo;
Double tolongitude = Double.parseDouble(this.flongitude);
Double tolatitude = Double.parseDouble(this.flatitude);
System.out.println("原文件名 : " + this.fiuploadFileName);
System.out.println("文件描述 : " + toinfo);
System.out.println("存放路径: " + toSrcPath);
System.out.println("存放文件名: " + toFilename);
System.out.println("当前经度 : " + tolongitude);
System.out.println("当前维度 : " + tolatitude);
File toFile = new File(toSrc);
writeFile(this.fiupload, toFile);
Files files = new Files(ts, toFilename, toSrcPath, toinfo, tolatitude,
tolongitude);
String result = filesService.addData(files);
System.out.println(result);
success = true;
return SUCCESS;
} private static void writeFile(File src, File dst) {
System.out.println(" == 文件写入 == ");
try {
InputStream in = null;
OutputStream out = null;
try { in = new BufferedInputStream(new FileInputStream(src),
BUFFER_SIZE);
out = new BufferedOutputStream(new FileOutputStream(dst),
BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
while (in.read(buffer) > 0) {
out.write(buffer);
}
} finally {
if (null != in) {
in.close();
}
if (null != out) {
out.close();
}
}
} catch (Exception e) { e.printStackTrace();
}
System.out.println(" == 写入成功! == ");
}

ExtJS:文件上传实例的更多相关文章

  1. PHP中,文件上传实例

    PHP中,文件上传一般是通过move_uploaded_file()来实现的.  bool move_uploaded_file ( string filename, string destinati ...

  2. PHP学习笔记--文件目录操作(文件上传实例)

    文件操作是每个语言必须有的,不仅仅局限于PHP,这里我们就仅用PHP进行讲解 php的文件高级操作和文件上传实例我放在文章的最后部分.--以后我还会给大家写一个PHP类似于网盘操作的例子 注意:阅读此 ...

  3. PHP+ExtJS 文件上传示例

    xtJS 4 有一个非常方便的文件上传组件,可以用来将文件上传到服务器.本文PHP教程UncleToo将介绍使用PHP和ExtJS实现文件上传功能. 首先,创建文件上传组件Ext.form.Panel ...

  4. Grails笔记三:完整的文件上传实例

    文件上传在web应用中是比较普遍的,相对于使用jsp等技术实现文件上传,Grails的文件上传着实让人喜爱,因为极其简单,让人看一遍就容易轻松记住!不多说,实例如下: 假设已有一个名为uploadFi ...

  5. Extjs文件上传问题总结

    本来文件上传是一个简单而常用的功能,但是,由于刚刚接触extjs,对extjs中的控件及其使用方法并不熟悉,导致本来一个很快就可以搞定的文件上传问题,弄了将近两天的时间.现将问题及解决办法发出来,供有 ...

  6. 自定义ExtJS文件上传

    日常工作中,一般文件上传都是跟随表单一起提交的,但是遇到form表单中有许多地方有文件上传时这种方式却不是很适用,以下是我工作中用的文件上传方式: { xtype: 'fileuploadfield' ...

  7. struts2+extjs文件上传完整实现(攻克了上传中的各种问题)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/shanhuhau/article/details/28617999 首先须要引入上传控件 <s ...

  8. SpringMVC+ajax文件上传实例教程

    原文地址:https://blog.csdn.net/weixin_41092717/article/details/81080152 文件上传文件上传是项目开发中最常见的功能.为了能上传文件,必须将 ...

  9. ASP.NET多文件上传实例

    在Web应用程序开发中,避免不了要用到上传文件这个功能,但以前上传文件是个很麻烦的事,现在有了.NET,文件上传变得轻而易举.下面的这个例子实现了多文件上传功能.可以动态添加输入表单,上传的文件数量没 ...

随机推荐

  1. 用reg文件把便携版sublime text 3添加到右键菜单

    假设sublime文件夹在C:\\Users\\T430i\\Downloads\\Sublime Text Build 3059 x64\\ 则: Windows Registry Editor V ...

  2. Select标签 根据value值默认选中 Jquery

    网上找了很多都是错的,不行的. 下面方法可以的 <script type="text/javascript"> $(document).ready(function() ...

  3. iOS7 CookBook精彩瞬间(一)property、selector细节、__unused

    1.我们常常使用nonatomic,很多人只知道它的效率较高,却不知道其含义,其含义是非线程安全的,也就是说多线程修改时不加锁,可能出现多个线程先后修改而成为脏数据的情况. 2.unsafe_unre ...

  4. shell入门之变量测试

    格式:test 测试条件 字符串测试: 注意空格: test str1 == str2 测试字符串是否相等 test str1 != str2 测试字符串是否不相等 test str1 测试字符串是否 ...

  5. 新手学python(1):解析XML与系统调用

    最近需要做一个项目,完成一批音乐的格式转换.由于之前并未学习过python,所以想借此机会学一下.在介绍自己的学习过程之前,先把项目简要描述一下.目前在一台服务器a上有几十万首原始的MP3音乐文件,现 ...

  6. iOS开发之一:入门介绍

    今天就介绍一下iOS开发的基本的东西,有很多东西都是经常用到的而我却经常记不住,所以还是写下来吧. iOS开发需要的开发工具是Xcode,而Xcode又必须运行在 OS X(苹果系统)环境下,所以我们 ...

  7. Java-IO之超类OutputStream

    图中我们可以看出,以字节为单位的输出流的公共父类是OutputStream: 从中我们可以看出,以字节为单位的输出流的公共父类是OutputStream: (1)OutputStream是以字节为单位 ...

  8. git常用技巧

    一般的过程: ①如果还没有库先用 git clone 克隆一个库. ②使用 git checkout master切换到master分支. ③使用 git pull 同步远程master分支(即git ...

  9. 【一天一道LeetCode】#88. Merge Sorted Array

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  10. ROS_Kinetic_08 ROS的集成开发环境(IDEs)之使用Eclipse

    ROS_Kinetic_08 ROS的集成开发环境(IDEs)之使用Eclipse ROS支持的IDEs比较丰富,这里以Eclipse为例介绍一下. 具体内容参考:http://wiki.ros.or ...