`
yun70345
  • 浏览: 4797 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Extjs上传,struts2 后台处理总结

阅读更多

1.在使用extjs上传附件时,需要引入extjs的上传插件

<script type="text/javascript" src="../js/ext/ux/fileuploadfield/FileUploadField.js/>"

 2.在对应的extjs组件中添加如下代码:

var entityForm = new Ext.form.FormPanel  ( {
	    layout : "form",
	    labelWidth : 90, // label settings here cascade unless overridden
	    fileUpload : true,//true表示上传附件
	    bodyStyle : 'padding:5px 5px 0',
	    waitMsgTarget : true,
	    defaults : {
	        width : 230
	    },
	    defaultType : 'textfield',
	    items : [{
	    xtype: 'fileuploadfield',  
            id: 'upload',  
            name: 'upload',//这里名称需要与struts2后台代码中的名称对应  
            fieldLabel: '上传中文LOGO',  
            emptyText: '请选择',
            buttonText:'',
            buttonCfg: {  
                iconCls: 'upload-icon'  
            }
           }]
	});

 3. struts2 后台代码

/**上传的文件,与页面中的name对应*/
 private File upload;
 
 /**strut2自动获得文件的名称,变量名称的格式规则为:上面的inputName+FileName*/
 private String uploadFileName;
 
 /**strut2自动获得文件的类型,变量名称的格式规则为:上面的inputName+ContentType*/
 private String uploadContentType;

 4.在处理类上引用struts2的文件上传的拦截器

@InterceptorRef(value="fileUploadStack")

@InterceptorRef(value="fileUploadStack")
public class EbHeaderAction{
}

 ps:这并非一个完整的例子,而是记录的几个关键步骤,以便日后碰到类似需求,可以方便处理

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics