Extjs上传文件到数据库_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Extjs上传文件到数据库

Extjs上传文件到数据库

 2013/10/23 18:55:35  JaneCrysteal  程序员俱乐部  我要评论(0)
  • 摘要:前端:varuploadForm=Ext.create('Ext.form.Panel',{region:'center',bodyStyle:'padding:0px0px00px;background-color:#DFE8F6',margin:'0000',xtype:'form',method:'POST',fileUpload:true,split:true,//autoScroll:true,//collapsible:true,layout:{type:'table'
  • 标签:上传 文件 数据库 数据 上传文件 JS
前端:
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>
发表评论
用户名: 匿名