ext上传文件代码


Js代码
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]
});

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代码
Java代码
private FormFile picture1;

private FormFile picture2;

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

private FormFile picture1;

private FormFile picture2;

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

action代码AddGameAction.java
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等方法,保存当前的数据

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

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等方法,保存当前的数据

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值