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等方法,保存当前的数据
将文件直接存入数据库中了.......
ext上传文件代码
最新推荐文章于 2024-07-12 09:52:04 发布