日期:2014-05-16 浏览次数:20535 次
Ext.onReady(function(){ var form = new Ext.form.FormPanel({ renderTo:'file', labelAlign: 'right', title: '文件上传', labelWidth: 60, frame:true, url: '../UpLoadServlet',//fileUploadServlet width: 300, height:200, fileUpload: true, items: [{ xtype: 'textfield', fieldLabel: '文件名', name: 'file', inputType: 'file'//文件类型 }], buttons: [{ text: '上传', handler: function() { form.getForm().submit({ success: function(form, response){ Ext.Msg.alert('信息', response.result.msg); }, failure: function(){ Ext.Msg.alert('错误', '文件上传失败'); } }); } }] }); });
var dialog = new Ext.ux.UploadDialog.Dialog({ autoCreate: true, closable: true, collapsible: false, draggable: true, minWidth: 400, minHeight: 200, width: 400, height: 350, permitted_extensions:['JPG','jpg','jpeg','JPEG','GIF','gif','xls','XLS'], proxyDrag: true, resizable: true, constraintoviewport: true, title: '文件上传', url:'../UpLoadServlet', reset_on_hide: false, allow_close_on_upload: true , upload_autostart: false }); //定义上传文件的按钮 var btnShow = new Ext.Button({ text:'上传文件', listeners:{ click:function(btnThis,eventobj){ dialog.show(); } } });
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); //往页面上传值 String mess=""; SmartUpload su = new SmartUpload(); try { //初始化操作 su.initialize(this.getServletConfig(),request,response); su.upload(); com.jspsmart.upload.File file = su.getFiles().getFile(0); //获得上传的文件另存的路径 String uploadPath=request.getParameter("uploadPath"); //创建保存上传文件的文件夹 java.io.File f = new File(uploadPath) ; if(!f.exists()){ f.mkdir(); } file.saveAs(file.getFileName()); mess="{'success':true,'message':'上传成功'}"; } catch(Exception e){ e.printStackTrace(); mess="{'success':true,'message':'上传失败'}"; } PrintWriter pw=response.getWriter(); System.out.println(mess); pw.println(mess); pw.flush(); pw.close(); }