/*
*
* This file is part of Ext JS 4
*
* Copyright (c) 2011 Sencha Inc
*
* Contact: http://www.sencha.com/contact
*
* GNU General Public License Usage This file may be used under the terms of the
* GNU General Public License version 3.0 as published by the Free Software
* Foundation and appearing in the file LICENSE included in the packaging of
* this file. Please review the following information to ensure the GNU General
* Public License version 3.0 requirements will be met:
* http://www.gnu.org/copyleft/gpl.html.
*
* If you are unsure which license is appropriate for your use, please contact
* the sales department at http://www.sencha.com/contact.
*
*/
Ext.require(['Ext.form.field.File', 'Ext.form.Panel', 'Ext.window.MessageBox']);
Ext.onReady(function() {
Ext.define('State', {
extend : 'Ext.data.Model',
autoLoad : false,
fields : [{
type : 'string',
name : 'text'
}, {
type : 'string',
name : 'flag'
}]
});
var store = Ext.create('Ext.data.Store', {
model : "State",
proxy : {
type : "ajax",
url : "./totosea/js/combobox_1.js",
reader : {
type : "json"
}
},
autoLoad : true
});
var upform = Ext.create('Ext.form.Panel', {
renderTo : 'adminfileupdata',
width : 500,
id : "upform",
frame : true,
title : '文件上传',
bodyPadding : '10 10 0',
x : 40,
y : 40,
defaults : {
anchor : '100%',
allowBlank : false,
msgTarget : 'side',
labelWidth : 100
},
items : [{
xtype : 'combobox',
fieldLabel : '文件用途',
emptyText : '请选择文件用途分类',
store : store,
displayField : 'text',
valueField : 'flag',
name : 'flag'
}, {
xtype : 'textfield',
fieldLabel : '自定义文件名称',
emptyText : '请自定义文件名称,必填!',
name : "uplname"
}, {
xtype : 'filefield',
id : 'form-file',
emptyText : '请选择本地文件',
fieldLabel : '上传地址',
name : 'upl',
buttonText : '上传',
buttonConfig : {
iconCls : 'upload-icon'
}
}],
buttons : [{
text : '上传',
handler : function() {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
url : 'uploadAdmin.do',
waitMsg : '正在上传您的文件,请耐心等候...',
success : function(form, action) {
Ext.Msg.alert('提示信息', "文件保存成功");
},
failure : function() {
Ext.Msg.alert("提示信息", "对不起,文件保存失败");
}
});
}
}
}, {
text : '重置',
handler : function() {
this.up('form').getForm().reset();
}
}]
});
});
[{
'text' : '可执行sql文件(TXT)',
'flag' : '1'
}, {
'text' : '普通文件',
'flag' : '2'
}]
/**
* 资源文件上传到服务器
*/
public void uploadAdmin() {
String flag = this.servletRequest.getParameter("flag");
String uplname = this.servletRequest.getParameter("uplname");
String filePath = this.getDocumentAdminPath() + uplFileName;
File file = new File(filePath);
/**
* 保存文件
*/
ResourceFile a = new ResourceFile();
a.setCreateDate(new Date());
a.setContentType(this.uplContentType);
a.setFilePath("/document/admin/" + uplFileName);
a.setFlag(Integer.parseInt(flag));
a.setExeNumber(0);
a.setExtension(ActionUtil.getExtention(uplFileName).substring(1));
a.setName(uplname);
/**
* 复制文件到磁盘
*/
ActionUtil.copy(upl, file);
try {
this.hibernateService.save(a);
} catch (Exception e) {
e.printStackTrace();
}
/**
* 返回结果
*/
// JSONObject json = new JSONObject();
// json.put("msg", "文件上传成功");
// json.put("success", "true");
// System.out.println(json.toString());
// JsonResult.json(json.toString(), servletResponse);
}
<action name="uploadAdmin" class="fileAction" method="uploadAdmin"> <interceptor-ref name="fileUpload"> <param name="allowedTypes"> application/vnd.ms-word, application/vnd.ms-excel, application/pdf, text/plain,application/kswps </param> <param name="maximumSize">104857600</param> <param name="savePath">/upload</param> </interceptor-ref> <interceptor-ref name="defaultStack" /> <result name="success">${successValue}</result> <result name="r" type="redirect">${successValue}</result> </action>