FLEX搭配JSP下载文件的例子

FLEX代码

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script>
  <![CDATA[
   public static function export():void{

   System.useCodePage = true;
   var url:String = "http://localhost:8080/flexSpring/exportExcel.jsp";
   var variables:urlvariables = new urlvariables();
   variables.fileType= "swf";
   variables.fileName="aaa"
   variables.filePath="/uploadFile/Dashboard.swf";
   var u:URLRequest = new URLRequest(url);
   u.data = variables;
   u.method = URLRequestMethod.POST;
   navigatetoURL(u,"_self");
  }
  ]]>
 </mx:Script>
 <mx:Button  label="test" click="export()"/>
</mx:Application>

JSP代码

<%@ page language="java" import="java.util.*,java.io.*,java.net.URLDecoder" pageEncoding="GBK"%>
<%@page contentType="application/msexcel;charset=GBK"%>
<%
 request.setCharacterEncoding("utf-8");
 InputStream is = request.getInputStream(); 
 BufferedReader tBufferedReader = new BufferedReader(new InputStreamReader(is));
 StringBuffer sb = new StringBuffer();
 String temp = new String("");
 while ((temp = tBufferedReader.readLine()) != null){
  sb.append(temp);
 }
 temp = sb.toString();
 String[] params = temp.split("&");
 HashMap<String,Object> paramMap = new HashMap<String,Object>();
 for(int i=0;i<params.length;i++){
  paramMap.put(params[i].split("=")[0],params[i].split("=")[1]);
 }
 String fileType = paramMap.get("fileType").toString();
 response.setHeader("Content-disposition","attachment;filename="+ new String(URLDecoder.decode(paramMap.get("fileName").toString()).getBytes(),"ISO8859_1") + "." + fileType.toLowerCase());
  try
     {
  Requestdispatcher dispatcher = request.getRequestdispatcher(URLDecoder.decode(paramMap.get("filePath").toString()));
  dispatcher.forward(request,response);
  response.flushBuffer();
  out.clear();
  out = pageContext.pushBody();
     }
     catch(Exception e)
     {
         e.printstacktrace();
     }
%>

这个例子和上个flex例子区别不大,唯一的就是变相的实现了flex下载和打开文件

相关文章

一:display:flex布局display:flex是一种布局方式。它即可以...
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何...
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些...
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周...
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后...
我在网页上运行了一个Flex应用程序,我想使用Command←组合键...