日期:2014-05-16 浏览次数:20391 次
完整代码下载:
http://download.csdn.net/detail/lc448986375/4575723
upload.js:
Ext.onReady( function(){ var form = Ext.create( 'Ext.form.Panel', { frame:true, title:'文件上传实例', width:300, height:100, renderTo:'upload', items:[ { xtype:'filefield', //与后台定义的File属性名必须相同 name:'file', fieldLabel:'上传', allowbBlank:false, msgTarget:'side', buttonText:'选择文件' } ], buttons:[ { text:'上传', handler:function(){ var form = this.up('form').getForm(); if(form.isValid()){ form.submit( { url:'user_upload', waitMsg:'正在上传', success:function(fp,o){ Ext.Msg.show( { title:'提示信息', msg:'文件上传成功,上传文件名为:'+o.result.fileFileName, buttons:Ext.Msg.OK } ) } } ) } } } ] } ) } )
package action; import java.io.File; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { //格式必须为"文件名"+FileName private String fileFileName; //必须与前台的name相同才可以接收到 private File file; private boolean success; public String upload(){ //对文件进行操作,这里只是输出一下文件名 System.out.println(fileFileName); success = true; return SUCCESS; } public String getFileFileName() { return fileFileName; } public void setFileFileName(String fileFileName) { this.fileFileName = fileFileName; } public File getFile() { return file; } public void setFile(File file) { this.file = file; } public boolean isSuccess() { return success; } public void setSuccess(boolean success) { this.success = success; } }