Flex File Download +tomcat Web application Server

Source: Internet
Author: User

Note the point:

The 1.filereference.download () method prompts the user to provide a location to save the file and start downloading from the remote URL. Direct load Request path download, no background support required.

2. For the Chinese name of the file, the two sides need to set the code:

First Flex side:

var download_request:urlrequest=new urlrequest (encodeURI (Stringutil.trim (URL)));
    • encodeURI (uri:string= "undefined"): String
Encodes a string as a valid URI (Uniform Resource Identifier). Converts the complete URI to a string in which all characters are encoded in the UTF-8 escape sequence, except for characters that belong to a small set of basic characters.
  
Then the Tomcat side:
Open the \apache-tomcat-7.0.39\conf\server.xml configuration file and locate the following configuration:
    <connector port= "8080" protocol= "http/1.1"               connectiontimeout= "20000"               uriencoding= "UTF-8"/ >

Modify or append the red portion of the content

Then restart the service.

Specific flex download-side code is as follows:

Filedownload.mxml

<?xml version= "1.0" encoding= "Utf-8"? ><s:application xmlns:fx= "http://ns.adobe.com/mxml/2009" xmlns:s= " Library://ns.adobe.com/flex/spark "xmlns:mx=" library://ns.adobe.com/flex/mx "minwidth=" 955 "minHeight=" > <fx:script><! [Cdata[import mx.controls.alert;import mx.utils.stringutil;protected function Button1_clickhandler (event: MouseEvent): void{//TODO auto-generated method Stubdownload ("http://192.168.191.5:8080/netcanvas_s/", " 360 Software Small Helper 20140508200748.png ");} private var fileref:filereference=new filereference ();/** * File Download * Backurl: Background server address * pathfilename: Downloaded file path + filename * */publi C function DownLoad (backurl:string,pathfilename:string): Void{fileref.addeventlistener (Event.complete, Completehandler); Fileref.addeventlistener (Securityerrorevent.security_error,securityerrorhandler); Fileref.addeventlistener (progressevent.progress, Progresshandler); Fileref.addeventlistener (IOErrorEvent.IO_ Error,ioshow) var Filenamearr:array=stringutil.trim (pathfilename). Split ('/'); var dECODENAME=FILENAMEARR[FILENAMEARR.LENGTH-1]; Intercept file name var url:string=backurl+pathfilename;var download_request:urlrequest=new urlrequest (EncodeURI (                                        Stringutil.trim (URL))); Fileref.download (Download_request,decodename); Download the file and add the default file name}//download into processing time private function Progresshandler (event:progressevent): Void{lbprogress.text = "downloaded" + (  event.bytesloaded/1024). toFixed (2) + "K, total" + (event.bytestotal/1024). toFixed (2) + "K"; var proc:uint = event.bytesloaded /event.bytestotal * 100;progress1.setprogress (proc, +);p rogress1.label= "Current progress:" + "" + proc + "%";} File Download Success Event private Function Completehandler (event:event): void {mx.controls.Alert.show ("File download succeeded");}   I/O error handling Private function Ioshow (evt:ioerrorevent) {alert.show (evt.tostring (), "IO error"); }//Security sandbox issue event Private function Securityerrorhandler (event:securityerrorevent) {alert.show (event.text);}]] ></fx:Script><fx:Declarations><!--Place non-visual elements (such as services, value objects) here--&GT;&LT;/fx:declarations><s:button x= "289" y= "149" label= "Download" click= "Button1_clickhandler (Event)"/&GT;&LT;MX: ProgressBar x= "y=" "width=" 457 "minimum=" 0 "mode=" manual "maximum=" + "id=" Progress1 "label=" Current progress: 0% "stylename= "MyFont" fontweight= "normal"/><mx:label x= "146" y= "98" width= "321" id= "lbprogress" stylename= "MyFont" textAlign = "Right"/></s:application>

Show effects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.