前几天写了一篇jsp页面利用ajaxFileUpload上传文件。如今把flex上传页面也分享出来:

前台页面

<?xml version="1.0" encoding="utf-8"?>
<s:HGroup xmlns:fx="<a target=_blank href="http://ns.adobe.com/mxml/2009">http://ns.adobe.com/mxml/2009</a>"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="hgroup1_creationCompleteHandler(event)"
    width="100%" height="30" >
 <fx:Script>
  <![CDATA[
   import mx.collections.ArrayList;
   import mx.controls.Alert;
   import mx.events.FlexEvent;
   private var file:FileReference = new FileReference;
   public var fileList:ArrayList;
   public var manualCheck:ManualCheck;
   
   protected function hgroup1_creationCompleteHandler(event:FlexEvent):void
   {
    // TODO Auto-generated method stub
//    file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,fileUploadCompleteHandler);
    file.addEventListener(Event.SELECT, fileSelect); 
//    file.addEventListener(IOErrorEvent.IO_ERROR,uploadError);
   }
   
   protected function button2_clickHandler(event:MouseEvent):void
   {
    // 浏览
    file.browse();
   }
   
   private function fileSelect(e:Event):void 
   {  
    if(fileList.getItemIndex(file) == -1){
     fileList.addItem(file);
    }
    fileName.text = file.name;
   }
   
//   private function fileUploadCompleteHandler(e:DataEvent):void{     
//    
//   }
   
   private function uploadError(e:IOErrorEvent):void{    
    this.cursorManager.removeBusyCursor();
    //获取后台的错误提示信息
    Alert.show("上传出错。","提示");
   }
   
   
   protected function button3_clickHandler(event:MouseEvent):void
   {
    // 删除
    fileList.removeItem(this.file);
    manualCheck.group.removeElement(this);
   }
   
  ]]>
 </fx:Script>
 <fx:Declarations>
  <!-- 将非可视元素(比如服务、值对象)放在此处 -->
  
 </fx:Declarations>
 <s:TextInput id="fileName" width="350"/>
 <mx:Button label="浏览" click="button2_clickHandler(event)" fontWeight="bold"
      overSkin="@Embed(source='/assets/dfpBtn/btnliulan2.png')"
      skin="@Embed(source='/assets/dfpBtn/btnliulan.png')"/>
 <mx:Button click="button3_clickHandler(event)"
      overSkin="@Embed(source='/assets/dfpBtn/deletebtn2.png')"
      skin="@Embed(source='/assets/dfpBtn/deletebtn.png')"/>
</s:HGroup>

as:

var file:FileReference = fileList.getItemAt(i) as FileReference;
var request:URLRequest=new URLRequest("s/upload/uploadFile");
request.data=new URLVariables();
request.data.orderRedoRecord=n; try{
file.upload(request,"file");
} catch (error:Error){
isSuccess = false;
Alert.show("文件上传失败");
}

后台java:

@RequestMapping(value = "/uploadFile")
@ResponseBody()
public String UploadFiles(@RequestParam(value = "file") MultipartFile file) {
String result = "";
if (!file.isEmpty()) {
try {
String attachName = file.getOriginalFilename();
logger.info(attachName); String filePath = "你的路径";
//此处省去业务代码
//FileUtils.saveDataToFile(file.getBytes(), filePath);
result = "上传成功";
} catch (Exception e) {
// TODO Auto-generated catch block
result = "上传失败";
e.printStackTrace();
}
}
return result;
}


Flex上传文件的更多相关文章

  1. Flex上传文件报“Error #2038”

    1.错误描述 ioerror: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 t ...

  2. Flex上传文件Java端解决中文乱码问题

    1.Flex端进行编码 public function encodeStr(str:String, charSet:String):String { var result:String =" ...

  3. Flex和Servlet结合上传文件

    Flex和Servlet结合上传文件 1.准备工作 (1)下载文件上传的组件,commons-fileupload-1.3.1.jar (2)下载文件输入输出jar,commons-io-2.4.ja ...

  4. 关于Extjs MVC模式上传文件的简单方式

    Extjs新手研究上传文件的事情估计是件很头痛的问题,毕竟,我就在头痛.最近两天一直在忙文件上传问题,终于小有收获. 用的是Extjs+MVC3.0+EF开发,语言为C#.前台window代码显示列内 ...

  5. Element-ui上传文件(删除、添加、预览)

    先看下效果是不是你所需要的.... 上传文件进度条后续会加上的.... 功能需求:默认为上传状态 1.未上传:点击可上传文件 2.已上传:点击可上传文件 (1).鼠标移入[删除] (2).鼠标点击[预 ...

  6. element ui实现手动上传文件,且只能上传单个文件,并能覆盖上传。

    element ui提供了成熟的组件场景,但实际工作中难免会遇到认(sha)真(diao)的产品.比如,最近遇到的,要求实现手动上传特定格式文件(用户点击“上传文件”按钮,确定之后,只是单纯选择了文件 ...

  7. IE8/9 JQuery.Ajax 上传文件无效

    IE8/9 JQuery.Ajax 上传文件有两个限制: 使用 JQuery.Ajax 无法上传文件(因为无法使用 FormData,FormData 是 HTML5 的一个特性,IE8/9 不支持) ...

  8. 三种上传文件不刷新页面的方法讨论:iframe/FormData/FileReader

    发请求有两种方式,一种是用ajax,另一种是用form提交,默认的form提交如果不做处理的话,会使页面重定向.以一个简单的demo做说明: html如下所示,请求的路径action为"up ...

  9. asp.net mvc 上传文件

    转至:http://www.cnblogs.com/fonour/p/ajaxFileUpload.html 0.下载 http://files.cnblogs.com/files/fonour/aj ...

随机推荐

  1. 关于闹钟设置AlarmManager类方法参数解释

    1.AlarmManager,顾名思义,就是“提醒”,是Android中常用的一种系统级别的提示服务,可以实现从指定时间开始,以一个固定的间隔时间执行某项操作,所以常常与广播(Broadcast)连用 ...

  2. IOS7 适配以及向下兼容问题

    1.所有的UIViewController加如下方法.     - (void) viewDidLayoutSubviews {         if ([[[UIDevice currentDevi ...

  3. Python 迭代器、生成器、递归、正则表达式 (四)

    一.迭代器&生成器 1.迭代器仅仅是一容器对象,它实现了迭代器协议.它有两个基本方法: 1)next 方法 返回容器的下一个元素 2)_iter_方法 返回迭代器自身.迭代器可以使用内建的it ...

  4. windows服务怎么向应用程序发消息(部署在同一台机,非SCOKET)

    命名管道:NamedPipeClientStream & NamedPipeClientStream 参考实例:http://msdn.microsoft.com/zh-cn/library/ ...

  5. 使用zxing生成二维码 - servlet形式

    因为项目有个功能需要打印二维码,因为我比较喜欢使用html+css+js实现,所以首先想到的是jquery.qrcode.js插件,这个插件可以用canvas和table生成二维码,效果也不错,不过对 ...

  6. centos 推荐使用epel源

    centos 推荐使用epel源 张映 发表于 2011-10-13 分类目录: linux 在dell r410上面装的是centos6,64的操作系统,用的163的源,我一直都是用163的源,比较 ...

  7. 解决TCP网络传输“粘包”问题

    当前在网络传输应用中,广泛采用的是TCP/IP通信协议及其标准的socket应用开发编程接口(API).TCP/IP传输层有两个并列的协议:TCP和UDP.其中TCP(transport contro ...

  8. USG 2210

  9. Smarty - 安装+入门小例子

    环境: smarty 1.在http://www.smarty.net/download下载最新smarty包,window选择zips,linux下选择tar.gz.以windows为例,下载后解压 ...

  10. JQuery - 根据节点获取对应的id,可用于留言板

    可以用于留言版的,点击展看和收起.显示评论等等功能. 效果: ----------------- html代码: JQuery代码: