flex文件下载
来源:互联网 发布:linux 进程退出日志 编辑:程序博客网 时间:2024/06/10 00:46
1flex端
<mx:Button label="下 载" click="download()"/>
//下载
public function download():void{
var str:String=this.uploadfiles.selectedIndex.toString();
if(str=="-1"){
Alert.show("请选中要下载的文件");
}else{
downloadfiles();
}
}
public function downloadfiles():void{
var loadid:String=this.uploadfiles.selectedItem.loadid;
if(loadid==null || loadid==""){
Alert.show("对不起,该文件还未上传");
}
var urlAddress:String=model.root+"/uploadFiles.do?method=download&loadid="+loadid;
//URLRequest可以捕获单个HTTP的所有信息
var url:URLRequest=new URLRequest(urlAddress);
var loadname:String=this.uploadfiles.selectedItem.loadname;
//download()方法提示用户提供文件的保存位置并开始从远程 URL 进行下载。
filedown.download(url,loadname);
}
protected override function createChildren():void{
super.createChildren();
filedown.addEventListener(Event.COMPLETE,onDownCompleted);
}
public function onDownCompleted(evt:Event):void{
this.resultlabel.visible=true;
var fileref:FileReference = evt.currentTarget as FileReference;
resultlabel.text = "文件名:" + uploadfiles.selectedItem.loadname+ "下载完毕!";
}
java后台(action)
/**
* 文件下载
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward download(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
log.info("Enter UploadFilesAction download===============");
// 被下载的文件id
String loadid = request.getParameter("loadid");
UploadFiles condition = this.uploadService.getFiles(loadid);
// 读取文件存放的目录
String filepath = this.getServlet().getServletContext().getRealPath("");
// 页面中的文件路径与服务器上的路径匹配(与服务器有关吗??)
// File file = new File(filepath, condition.getLoadpath());
File file = new File(condition.getLoadpath());
// 如果文件存在(读取文件流)
if (file.exists()) {
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Dispostion", "attachment;filename="
+ new String(condition.getLoadname().getBytes(),
"iso-8859-1"));
FileInputStream fis = new FileInputStream(file);
OutputStream ops = response.getOutputStream();
byte[] b = new byte[1024];
int real = fis.read(b);// 每次读取1024个字节
while (real > 0) {
ops.write(b, 0, real);
real = fis.read(b);
}
ops.close();
fis.close();
}
return null;
}
- flex 下载文件
- flex文件下载
- FLEX文件下载
- flex 下载文件
- Flex文件下载
- Flex实现文件下载
- Flex上载和下载文件
- flex 文件上传及下载
- flex 文件上传与下载
- flex上传和下载文件
- flex 文件上传与下载
- flex 文件下载和上传
- flex上传和下载文件
- java-flex 批量下载文件-压缩下载
- flex 导出文件&导出图片&文件下载
- 【心得】Flex中的文件上传与下载
- Flex中的文件上传与下载
- flex filereference+httphandler实现文件上传/下载
- 收集嵌入式数据库Sqlite移植资料
- 云计算来临,我们将何去何从
- WIFI
- flex上传文件
- js运行时异常与table中的内容
- flex文件下载
- JFreeChart中柱状图的详细设置
- Java程序通过weka调用libsvm和liblinear的方法
- 硬件面经 zz
- 由baidu被黑而想到的
- Input和Img等元素垂直对齐的方法
- WinAPI: WinExec - 运行外部程序
- hook 基本概念
- TinyXML:一个优秀的C++ XML解析器(转自Phinecos(洞庭散人))