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;
}
Flex上传文件的更多相关文章
- Flex上传文件报“Error #2038”
1.错误描述 ioerror: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 t ...
- Flex上传文件Java端解决中文乱码问题
1.Flex端进行编码 public function encodeStr(str:String, charSet:String):String { var result:String =" ...
- Flex和Servlet结合上传文件
Flex和Servlet结合上传文件 1.准备工作 (1)下载文件上传的组件,commons-fileupload-1.3.1.jar (2)下载文件输入输出jar,commons-io-2.4.ja ...
- 关于Extjs MVC模式上传文件的简单方式
Extjs新手研究上传文件的事情估计是件很头痛的问题,毕竟,我就在头痛.最近两天一直在忙文件上传问题,终于小有收获. 用的是Extjs+MVC3.0+EF开发,语言为C#.前台window代码显示列内 ...
- Element-ui上传文件(删除、添加、预览)
先看下效果是不是你所需要的.... 上传文件进度条后续会加上的.... 功能需求:默认为上传状态 1.未上传:点击可上传文件 2.已上传:点击可上传文件 (1).鼠标移入[删除] (2).鼠标点击[预 ...
- element ui实现手动上传文件,且只能上传单个文件,并能覆盖上传。
element ui提供了成熟的组件场景,但实际工作中难免会遇到认(sha)真(diao)的产品.比如,最近遇到的,要求实现手动上传特定格式文件(用户点击“上传文件”按钮,确定之后,只是单纯选择了文件 ...
- IE8/9 JQuery.Ajax 上传文件无效
IE8/9 JQuery.Ajax 上传文件有两个限制: 使用 JQuery.Ajax 无法上传文件(因为无法使用 FormData,FormData 是 HTML5 的一个特性,IE8/9 不支持) ...
- 三种上传文件不刷新页面的方法讨论:iframe/FormData/FileReader
发请求有两种方式,一种是用ajax,另一种是用form提交,默认的form提交如果不做处理的话,会使页面重定向.以一个简单的demo做说明: html如下所示,请求的路径action为"up ...
- asp.net mvc 上传文件
转至:http://www.cnblogs.com/fonour/p/ajaxFileUpload.html 0.下载 http://files.cnblogs.com/files/fonour/aj ...
随机推荐
- 抽象工厂模式和autofac的使用总结
抽象工厂模式和依赖注入的使用目的都是降低对象直接依赖耦合关系,应该说依赖注入是抽象工厂模式的一种升华,功能更强大. 说到抽象工厂的模式,一般都要先解释下简单工厂,简单工厂就是将对象的实例化抽取出来形成 ...
- PHP - __clone 对象克隆
<?php /** * 此例子解释什么是深克隆. * 克隆学生类. */ class Student { public $name = '张三'; public $age = 12; //所属老 ...
- 判断圆和矩形是否相交C - Rectangle and Circle
Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...
- ARM流水线(pipeline)
- 发送邮件给某人:mailto标签
mailto标签 1.标签最简式 <a href="mailto:xxx@xx.com">联系站长</a> 2.标签帮你填抄送地址 <a href=& ...
- java计算两个日期相差多少天
java计算两个日期相差多少天 public class DateUtil{ public static int betweenDays(Date startDate, Date endDate ) ...
- Jekyll搭建过程详解
原先博客用Jekyll搭建在Github上,近来访问缓慢,而且markdown不太方便写,故决定在博客园安个新家. 文章见Github博客: 搭建过程:http://wuxichen.github.i ...
- matlab绘图方法汇总
Matlab画图 强大的画图功能是Matlab的特点之中的一个,Matlab提供了一系列的画图函数,用户不须要过多的考虑画图的细节,仅仅须要给出一些基本參数就能得到所需图形,这类函数称为高层画图函数. ...
- 多个线程怎样操作同一个epoll fd
自己曾经做一个接口server时候,这样的场景下我的设计是多个线程操作同一个epoll fd.彼时,我的理由是epoll的系列函数是线程安全的. 当然有人不理解为什么会有多个线程操作同一个epoll ...
- PHP - 四级单词lrc文件解析为txt
原始文件: 转换后文件: php代码: 首先根据需要更改文件路径. 转换后存放的文件要事先创建,为txt文件. 核心代码:正则表达式替换: <?php header('Content-type: ...