论坛首页 AJAX版 EXT

struts1.2 + Ext2.0实现多文件上传

浏览 403 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2008-07-24
上传界面代码
var gameFrom = new Ext.form.FormPanel({
	width:300,
	height:400,
	fileUpload:true,
	frame:true,
	bodyStyle: 'padding:5px 5px 0',
	labelAlign:'center',
	items:[
		new Ext.form.TextField({fieldLabel:'游戏截图1',name:'picture1',inputType:'file',allowBlank:false}),
		new Ext.form.TextField({fieldLabel:'游戏截图2',name:'picture2',inputType:'file'}),
		new Ext.form.TextField({fieldLabel:'游戏截图3',name:'picture3',inputType:'file'}) 
		//这里的名字picture1,picture2,picture3和form里面的对应,使用jsp的时候名字和form对应也能传上去
		//相信生成的JS代码也是像<input type="file" name="picture1"/>这样的吧
		//fileUpload:true == enctype="multipart/form-data" 这句吧
	],
	buttons:[
		{text:'添加',handler:function(){
				if(game_form.form.isValid()){
					game_form.form.submit({
						method:'POST',
						url:'../admin/addGame.do',
						waitMsg:'游戏添加中...',
						success:function(){Ext.MessageBox.alert('添加信息','添加成功');},
						failure:function(){Ext.MessageBox.alert('添加信息','添加失败');}
						
					});
				}else{
					Ext.MessageBox.alert('提示', '请完整填写表单');
					return;
				}
				add_dlg.hide();
	
		}},
		{text:'取消',handler:function(){
				add_dlg.hide();
			}
		}
	]
});

var addGame_dlg = new Ext.Window({
	title:'添加游戏截图',
	layout:'fit',
	height:540,
	width:650,
	autoDestroy : true,
	closeAction:'hide',
	modal:true,
	items:[gameFrom]
});

form代码
private FormFile picture1;

private FormFile picture2;

private FormFile picture3;
省略了get和set方法......

action代码AddGameAction.java
try {
	FormFile picture1 = gameInfoForm.getPicture1();
	gameInfo.setPictureMain(org.hibernate.Hibernate.createBlob(picture1
			.getInputStream()));

	FormFile picture2 = gameInfoForm.getPicture2();
	gameInfo.setPicture1(org.hibernate.Hibernate.createBlob(picture2
			.getInputStream()));

	FormFile picture3 = gameInfoForm.getPicture3();
	gameInfo.setPicture2(org.hibernate.Hibernate.createBlob(picture3
			.getInputStream()));
} catch (Exception e) {
	e.printStackTrace();
}
下面就是调用save等方法,保存当前的数据

将文件直接存入数据库中了.......



但是这样MS只是适合小的文件上传,没试过太大的文件
另外向高手们讨教个问题:ext占用客户端的资源越来越多有什么解决办法?
   
论坛首页 AJAX版 EXT

跳转论坛:
JavaEye推荐