EXT学习教程:http://www.cnblogs.com/iamlilinfeng/category/385121.html
Ext文件上传:
例子用到的jar:
1.upload.js
/* case of upload */ Ext.onReady(function(){ //初始化标签中的Ext:Qtip属性。 Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; /* var imageBox = new Ext.BoxComponent({ autoEl:{ //style: 'width:150px;height:150px;margin:0px auto;border:1px solid #ccc; text-align:center;padding-top:20px;margin-bottom:10px', style:'width:150px;height:150px;border:1px solid #ccc;text-align:center', tag:'div', id:'showImage' }, width:333, height:277 });*/ var upload_form = new Ext.form.FormPanel({ title: '', baseCls:'x-plain', labelWidth:70, labelHeight:150, fileUpload:true, defaultType : 'textfield', items:[{ xtype:'textfield', fieldLabel:'select file', name:'userfile', id:'userfile', inputType:'file', anchor:'95%' }] }); var win_upload = new Ext.Window({ title:'Upload :', width:444, height:140, bodyStyle : 'padding:10px 10px 10px 10px;', resizable:true, modal:true, closable:true, maximizable:true, minimizable:true, buttonAlign:'right', items:[upload_form], buttons:[{ text:'reset', handler:function(){ upload_form.getForm().reset(); } },{ text:'upload', handler:function(){ if(upload_form.getForm().isValid()){ if(Ext.getCmp('userfile').getValue() == ''){ Ext.Msg.alert('Warm :','please choose file!'); return; } /* Ext.Msg.show({ title:'waiting:', waitMsg:'uploading...', progressText:'', width:300, progress : true, closable : false, animEl : 'loding' });*/ upload_form.getForm().submit({ method:'POST', url:'uploadServlet', waitMsg:'uploading...', success:function(upload_form,action){ //var path = Ext.getCmp('userfile').getValue(); //document.getElementById('showImage').innerHTML = '<img src="'+path+'" />'; Ext.Msg.alert('success:','upload success!'); //win_upload.hide(); }, failure:function(upload_form,action){ Ext.Msg.alert('failure:','upload failure!'); } }); } } }] }); win_upload.show(); });
2.uploadServlet.java
package servlet; import java.io.File; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.json.JSONObject; /** * Servlet implementation class uploadServlet */ public class uploadServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public uploadServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); try { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload fileUpload = new ServletFileUpload(factory); fileUpload.setHeaderEncoding("UTF-8");// 解决中文名乱码 List<FileItem> fileItems = fileUpload.parseRequest(request); for(FileItem item:fileItems){//忽略其他表单信息 if (!item.isFormField()) { String name = ""; String BrowserType = request.getHeader("User-Agent").toLowerCase().toString(); //浏览器判断 if (BrowserType.indexOf("firefox")>0 ||BrowserType.indexOf("chrome")>0) { name = item.getName(); }else{ name = item.getName(); String [] names = name.split("\\\\");// (IE浏览器绝对路径,split获取文件名及后缀) regex为\\\\,因为在java中\\表示一个\,而regex中\\也表示\,所以当\\\\解析成regex的时候为\\。 name = names[names.length-1]; } File uploadFile = new File("E:\\",name); item.write(uploadFile); } } // JSONObject obj = new JSONObject(); obj.put("success","true"); response.getWriter().print(obj.toString()); } catch (Exception e) { e.printStackTrace(); // TODO: handle exception } } }
相关推荐
Extjs 文件上传 strut2
Extjs4文件上传,后台struts2
功能强大的Struts2.0+Extjs实现的文件上传,包含文件上传进度,文件的下载,压缩,解压多文件删除等
批量上传文件,完整的列子,部署既可以使用,
ExtJS文件上传示例 正常人都看得懂 ccccccccccccccccccccccccccccccc
ExtJS验证文件上传类型,详细讲述ExtJS如何验证文件上传文件的类型!
1.多文件上传 2.支持拖动上传 3.支持图片压缩 4.支持图片合并 5.文件排序 可扩展实时图片预览 api //初始化画板 initCanvas //上传文件窗口 uploadWindow //初始化选择文件列表源 initStore(files) //base64路径转...
extjs 多文件上传extjs 多文件上传
用Ext编写的多文件上传组件,已封装。 支持多文件上传,文件下载,文件删除,
支持 自由添加和减少上传文件个数的Extjs多文件上传源代码,10分绝对值得,要注意的一点就是jsp里面引用的Ext的js和css要是2.2版本的
对应的描述看本人博文《ExtJS4 上传文件类型和大小的判断方法(实例) 》:http://blog.csdn.net/biboheart/article/details/10579175 在这里不具体描述了。看题也大概可以知道这些代码实现了什么应用。
struts2+extjs3的单/多文件上传,后台也可以不用struts2,前台也可以去掉extjs,资源包含所需要的所有JAR包,无需另外下载,代码量绝对精简易懂。
EXTJS MultiFileUploadField 多文件 上传
实现了多文件上传,下载,压缩,解压缩,用struts2.0+Extjs实现,是第二部分,分享一下希望对大家有所帮助
NULL 博文链接:https://dejazhan.iteye.com/blog/870539
官方或网上ExtJS实现多文件上传的UploadDialog只适用于ExtJS2.x,我经过修改使其使用于ExtJS3.x,并在修改时尽量尊重于原始功能代码,请大家放心使用!
Java+Extjs实现单文件上传
组件库 博文链接:https://zjnbshifox.iteye.com/blog/123399
extjs的java版本的上传文件进度条