Ext上传文件

/*
 * 
 * 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>

转载于:https://www.cnblogs.com/tatame/archive/2012/05/04/2483417.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值