zoukankan      html  css  js  c++  java
  • Flex上传文件

    前几天写了一篇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;
    }









    
  • 相关阅读:
    AC日记——可能的路径 51nod 1247
    AC日记——[国家集训队2011]旅游(宋方睿) cogs 1867
    近期将要学习的内容(flag)
    Cogs 734. [网络流24题] 方格取数问题(最大闭合子图)
    Cogs 746. [网络流24题] 骑士共存(最大独立集)
    Cogs 729. [网络流24题] 圆桌聚餐
    [网络流24题]飞行员配对方案问题
    Hdu 3549 Flow Problem(最大流)
    Cogs 14. [网络流24题] 搭配飞行员(二分图匹配)
    Cogs 728. [网络流24题] 最小路径覆盖问题
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5151452.html
Copyright © 2011-2022 走看看