extjs采用fileupload进行文件上传后台实现
前台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进行文件上传后台实现的更多相关文章
- zt对于C#中的FileUpload解决文件上传大小限制的问题设置
对于C#中的FileUpload解决文件上传大小限制的问题设置 您可能没意识到,但对于可以使用该技术上载的文件的大小存在限制.默认情况下,使用 FileUpload 控件上载到服务器的文件最大为 4M ...
- 使用fileupload实现文件上传
一. fileupload组件工作原理 先来张图片, 帮助大家理解 fileupload核心API 1. DiskFileItemFactory构造器1) DiskFileItemFactory() ...
- SpringMvc 文件上传后台处理
springMVC后台参数是通过MultipartFile类来转化Request的文件上传,但需要apache下fileupload的jar包做支持. 在springMVC的dispatcher-co ...
- zk FileUpload(文件上传)
<button label="上传 Image" upload="true,maxsize=1073741824"> <attribute n ...
- asp.net web常用控件FileUpload(文件上传控件)
FileUpload控件的主要中能:向指定目录上传文件,该控件包括一个文本框和一个浏览按钮. 常用的属性:FileBytes,FileContent.FileName.HasFile.PostedFi ...
- Apache Commons fileUpload实现文件上传之一
需要两个jar包: commons-fileupload.jar Commons IO的jar包(本文使用commons-io-2.4.jar) 利用Servlet来实现文件上传. package ...
- Spring MVC使用commons fileupload实现文件上传功能
通过Maven建立Spring MVC项目,引入了Spring相关jar依赖. 1.为了使用commons fileupload组件,需要在pom.xml中添加依赖: <properties&g ...
- Apache Commons FileUpload 实现文件上传
Commons FileUpload简介 Apache Commons是一个专注于可重用Java组件开发的 Apache 项目.Apache Commons项目由三个部分组成: 1.Commons P ...
- 实用ExtJS教程100例-009:ExtJS Form无刷新文件上传
文件上传在Web程序开发中必不可少,ExtJS Form中有一个filefield字段,用来选择文件并上传.今天我们来演示一下如何通过filefield实现ExtJS Form无刷新的文件上传. 首先 ...
随机推荐
- Android SDK Manager更新不了的解决办法
android SDK Manager更新不了,出现错误提示:"Failed to fetch URL..."! 可以用以下办法解决: 使用SDK Manager更新时出现问题 F ...
- JavaScript学习——内置属性
在js中,几乎所有的对象都是同源对象,都继承Object对象.对象的内置属性指的是它们作为Object实例所具有的属性,这些属性通常反映对象本身的基本信息和数据无关.因此我们称它们为元属性.这些属性通 ...
- JS鼠标滑轮事件的写法和按键的事件
在body注册一下滑轮事件 <body onload="win_onload();"></body> 然后JS代码如下: function win_onlo ...
- 做fzu oj 1045 做减法学到的sprintf()函数
题目 做题一直输不出答案,于是就上网去百度了这题的解题,发现解答十分的简短,而且其中我看见了平时没见过的函数,sprintf(). 于是就百度sprintf()的使用. 如下: 函数功能:把格式化的数 ...
- Codeforces Round #313 (Div. 2) E. Gerald and Giant Chess (Lucas + dp)
题目链接:http://codeforces.com/contest/560/problem/E 给你一个n*m的网格,有k个坏点,问你从(1,1)到(n,m)不经过坏点有多少条路径. 先把这些坏点排 ...
- 编译ffmpeg(iOS)
一,x264库的编译 首先到http://www.videolan.org/developers/x264.html下载x264的库,然后解压,修改文件夹名称为x264 二,下载ffmpeg2 ...
- ASP.NET MVC- 在Area里使用RedirectToAction跳转出错的解决方法
mvc使用Area分区开发后,存在不同Area之间的跳转,需要为每个区间添加Area规则,如下: 按 Ctrl+C 复制代码 using System.Web.Mvc; namespace web.A ...
- C#中利用委托实现多线程跨线程操作
在使用VS2005的时候,如果你从非创建这个控件的线程中访问这个控件或者操作这个控件的话就会抛出这个异常.这是微软为了保证线程安全以及提高代码的效率所做的改进,但是也给大家带来很多不便. 其实解决这个 ...
- Hadoop集群基准测试
hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-2.2.0-tests.jar TestDFSIO -wri ...
- Firefox插件一键切换兼容IE
转载:http://mozilla.com.cn/thread-42137-1-1.html 让火狐兼容IE的双核扩展,一键切换至IE内核,网银支付无忧愁.支持Adblock plus和FireGes ...