Extjs上传文件到数据库

1 篇文章 0 订阅
1 篇文章 0 订阅
前端:
var uploadForm=Ext.create('Ext.form.Panel', {
region: 'center',
bodyStyle : 'padding: 0px 0px 0 0px; background-color: #DFE8F6',
margin: '0 0 0 0',
xtype: 'form',
method : 'POST',
fileUpload: true,
split: true,
//autoScroll:true,
//collapsible: true,
layout : {
type : 'table',
columns: 1
},
bodyStyle: 'background:#DFE8F6; ',
fieldDefaults: {
labelAlign: 'right',
labelWidth: 45,
width:300,
msgTarget: 'side',
padding:10
},
items: [
{
id:"question.questionId_upload",
xtype:"textfield",
name: 'question.questionId',
hidden:true
},
{
//xtype:'filefield',
id:'upload',
inputType : "file",
xtype : 'textfield',
emptyText: '请选择附件',
//allowBlank: false,
fieldLabel : '附件',
buttonText:"浏览",
name : 'file'
}
],
buttons: [
{
text: '确定',
listeners : {
click : function(btn, e, eOpts) {
if (uploadForm.getForm().isValid()) {
Ext.Msg.confirm("请确认?","确定上传?", function(button,text){
if(button=='yes'){
Ext.yh.form.submit({"form":uploadForm,
"url": basePath+'/system/uploadFile.action',
success : function(options_) {
//成功
//alert("----"+options_.result.entity.contentStr);
Ext.getCmp("question.questionId").setValue(options_.result.entity.questionId);
Ext.getCmp("question.questionId_upload").setValue(options_.result.entity.questionId);
win_2.hide();
},
failure : function(options_) {
//失败
win_2.hide();
}
});
}else{
return false;
}
});

}
}
}
},
{
text:"关闭",
xtype:'button',
handler:function(){
win_2.hide();
}
}
]
});
注意事项:panel中必须设置为fileUpload: true
后台Action:
/**
* 上传文件
* @return
*/
public String saveQuestion() throws Exception{
//try {
result = new ExtResult();
System.out.println(file);
if(file!=null){
question.setFileName(fileFileName);
String fileType[]=fileFileName.split("\\.");
question.setFileType(fileType[1]);
question.setQuestionFiles(getBytesFromFile(file));
}
questionService.saveOrUpdate(this.getUser(), question);
result.setEntity(question);
result.setMsg(Constants.OPT_SUCCESS);
//} catch (Exception e) {
// TODO: handle exception
//erro(e);
//}
return SUCCESS;
}
配置文件XML:
<action name="uploadFile" class="com.org.web.system.action.QuestionAction" method="saveQuestion">
<result name="success" type="json">
<param name="root">result</param>
<param name="contentType">text/html;charset=utf-8</param>
<param name="excludeProperties">null</param>
</result>
</action>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值