1. In this part, we focus on server side programming:
1) At what format did the data sent from Flex?
2) How did Servlet get data sent from Flex?
3) How did Servlet send response to Flex to notify upload finished?
4) How to make it easier for common file upload?
2. Use commons-io-2.4.jar and commons-fileupload-1.3.jar for easier file upload
package edu.xmu.servlet; import java.io.File; import java.io.IOException; import java.util.Iterator; 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.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; public class FileUploadServlet extends HttpServlet { private int maxPostSize = 1024 * 1024 * 1024; private String uploadPath = "E:/SampleUploadFolder/"; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("doGet"); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("doPost"); req.setCharacterEncoding("UTF-8"); // If we don't add this, garbled may occur with Chinese resp.setContentType("text/html;charset=UTF-8"); // Set the minimal file size DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(1024 * 2); // Set the max file size ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(maxPostSize); List<FileItem> fileItems = null; try { fileItems = upload.parseRequest(req); Iterator<FileItem> iter = fileItems.iterator(); while (iter.hasNext()) { FileItem fileItem = iter.next(); if (!fileItem.isFormField()) { String fileName = fileItem.getName(); System.out.println("fileName = " + fileName); fileItem.write(new File(uploadPath, fileName)); } } } catch (FileUploadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
3. Actually the server don't have to send message to Flex explicitly. In Flex fileReference will monitor on file upload process.
Comments:
1)May have java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException
A: Don't use UserLibrary. Copy commons-io-2.4.jar and commons-fileupload-1.3.jar into WebRoot/WEB-INF/lib folder instead.
相关推荐
Adobe Flex 4: Training from the Source Volume 1 解压密码:肇庆学院主页地址(www开头的)
Flex4:开发RIA应用程序.pdf Flex4的入门教程
手把手教你进入flex技术佳境,我认为是目前位置最好的一本flex4开发教程
该书为adobe flex4认证的内部培训教材,以Adobe Flash Builder 4为基础培训,目前市面上的flex4的教材太少,这个发上来大家一起看看吧
从Flex3环境的搭建到一般开发情景下Flex3的界面操作,以及ActionScript语言的介绍、Flex中的数据绑定、如何通过E4X操作XML、一般数据显示控件的使用,再到Flex特有的特效运用、样式主题,以及程序的发布都有全面的...
Adobe Flex 2: Training from the Source,看到有不少人在找~~~ 这本没有上传完整,请需要的朋友下载《Adobe Flex 2: Training from the Source(改)》这本~~~
Flex 4 demonstrates how to get started without getting bogged down in technical detail or academic edge cases. In this book, User Friendly cartoon characters offer commentary and snide side comments,...
NULL 博文链接:https://fzlihui.iteye.com/blog/953140
Flex_4:开发RIA_应用程序.pdf Flex_4:开发RIA_应用程序.pdf
flex三种实现滚动条方式,其实是两种,样式的以两种表现形式写出了。然后,自定了一个滚动条
Flex_3_与_Flex_4_之间的区别
FLEX调用Servlet连接数据库源码
本文简单介绍了Flex如何通过servlet连接数据库(Access)。使用的是<mx:HttpService>给后台传递数据的方法。 本文开发使用的软件: Flex3-eclipse plugin Tomcat 6.0 Microsoft access 2003 Eclipse 3.3 ...
《Flex 4权威指南》是Adobe公司的官方教程,以课程的形式逐步讲解了如何用Flex 4开发一个完整的网上杂货商店应用程序,这个杂货商店能够动态显示数据和图像,并帮助用户完成结账流程,到数据提交至服务器为止。...
Flex_RPC错误大全
Connect Flex to Adobe's powerful ColdFusion application server, and start to work with Flex applications powered by dynamic server-side code. * Learn how states can smoothly transition your ...
Connect Flex to Adobe's powerful ColdFusion application server, and start to work with Flex applications powered by dynamic server-side code. * Learn how states can smoothly transition your ...
Flex SDK 4.5 Part 4 Webgame Develop
Flex4.6+java+servlet上传图片例子+图片上传预览
FLEX4 s:dataGrid单元格弹出可文本,就是单击单元格弹出自己定义的一个组件,