ExtJS:文件上传实例
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:文件上传实例的更多相关文章
- PHP中,文件上传实例
PHP中,文件上传一般是通过move_uploaded_file()来实现的. bool move_uploaded_file ( string filename, string destinati ...
- PHP学习笔记--文件目录操作(文件上传实例)
文件操作是每个语言必须有的,不仅仅局限于PHP,这里我们就仅用PHP进行讲解 php的文件高级操作和文件上传实例我放在文章的最后部分.--以后我还会给大家写一个PHP类似于网盘操作的例子 注意:阅读此 ...
- PHP+ExtJS 文件上传示例
xtJS 4 有一个非常方便的文件上传组件,可以用来将文件上传到服务器.本文PHP教程UncleToo将介绍使用PHP和ExtJS实现文件上传功能. 首先,创建文件上传组件Ext.form.Panel ...
- Grails笔记三:完整的文件上传实例
文件上传在web应用中是比较普遍的,相对于使用jsp等技术实现文件上传,Grails的文件上传着实让人喜爱,因为极其简单,让人看一遍就容易轻松记住!不多说,实例如下: 假设已有一个名为uploadFi ...
- Extjs文件上传问题总结
本来文件上传是一个简单而常用的功能,但是,由于刚刚接触extjs,对extjs中的控件及其使用方法并不熟悉,导致本来一个很快就可以搞定的文件上传问题,弄了将近两天的时间.现将问题及解决办法发出来,供有 ...
- 自定义ExtJS文件上传
日常工作中,一般文件上传都是跟随表单一起提交的,但是遇到form表单中有许多地方有文件上传时这种方式却不是很适用,以下是我工作中用的文件上传方式: { xtype: 'fileuploadfield' ...
- struts2+extjs文件上传完整实现(攻克了上传中的各种问题)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/shanhuhau/article/details/28617999 首先须要引入上传控件 <s ...
- SpringMVC+ajax文件上传实例教程
原文地址:https://blog.csdn.net/weixin_41092717/article/details/81080152 文件上传文件上传是项目开发中最常见的功能.为了能上传文件,必须将 ...
- ASP.NET多文件上传实例
在Web应用程序开发中,避免不了要用到上传文件这个功能,但以前上传文件是个很麻烦的事,现在有了.NET,文件上传变得轻而易举.下面的这个例子实现了多文件上传功能.可以动态添加输入表单,上传的文件数量没 ...
随机推荐
- 在Ubuntu12.04上安装图形化配置与window共享的samba服务器
1.安装samba图形化配置界面 sudo apt-get install system-config-samba 2.启动图形化配置界面 3.添加用户,最好是要用adduser命令去添加 具体配置可 ...
- 28 自定义View画坐标和柱状图
自定义View类 RectView.java package com.qf.sxy.day29_customview.widget; import android.content.Context; i ...
- main函数之后的调用
main函数代表进程的主线程.程序开始执行时,系统为程序创建一个进程,main函数其实并不是首先被调用的函数,而是操作系统调用了C/C++运行期启动函数,该函数负责对C/C++ 运行期库进行初始化.它 ...
- Cartographer资料分享
中文资料稍后补充 Introducing Cartographer By Tully Foote on October 5, 2016 10:11 AM From Damon Kohler, Wolf ...
- 3-sum问题
给定一个整数数组,判断能否从中找出3个数a.b.c,使得他们的和为0,如果能,请找出所有满足和为0个3个数对. #define SIZE 10 void judgeAndPut(int* arr, i ...
- 21 PagerTabStrip-PagerTitleStrip-viewPager
PagerTabStrip:可以点击跳转到对应viewPager界面 PagerTitleStrip:不可点击 在eclipse开发时如果目标版本为API23那么会有不显示的问题 解决:更换v4包 解 ...
- 剑指Offer--图的操作
剑指Offer–图的操作 前言 企业笔试过程中会涉及到数据结构的方方面面,现将有关图的深度优先搜索与广度优先搜索进行整理归纳,方便日后查阅. 在已做过的笔试题目中,可用DFS解决的题目有: & ...
- 从一个简洁的进度刻度绘制中了解自定义View的思路流程
先看效果(原谅我的渣像素),进度的刻度.宽度.颜色可以随意设定: [项目github地址: https://github.com/zhangke3016/CircleLoading] 实现起来并不难, ...
- Blue Path(基于cocos2dx 3.0)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=498 iTunes下载:http ...
- 04 Spinner 列表选中
<span style="font-size:18px;"> <?xml version="1.0" encoding="utf-8 ...