ExtJs3.2.2+Struts2实现文件的上传
Struts2支持Common-FileUpload框架和COS框架,不过Struts2又在这些上传项目的基础上做了封装,屏蔽了上传文件的代码编程差别。
var uploadForm = new Ext.form.FormPanel({......fileUpload : true,//注意这个必须的,否则文件内容并未上传上去items:[{xtype : 'textfield',fieldLabel : '音源上传',id : 'uploadFile',name : 'uploadFile',inputType : 'file',//指定是文件类型输入框vtype : 'fileType',allowBlank : false}]......})
private File xxx;private String xxxFileName;private String xxxContentType;
private static void copy(File src, File dst) {//TODOtry {InputStream in = null;OutputStream out = null;try {in = new BufferedInputStream(new FileInputStream(src),BUFFER_SIZE);out = new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZE);byte[] buffer = new byte[BUFFER_SIZE];while (in.read(buffer) > 0) {out.write(buffer);}} finally {if (null != in) {in.close();}if (null != out) {out.close();}}} catch (Exception e) {e.printStackTrace();}}