Question: Flex 3.5 或 Flex 4 + pureMVC + BlazeDs + Java 1.6.0_18 + Spring + Hibernate 环境下开发的App,在做上传导入文件时,遇到了浏览器兼容问题。
在IE下,导入完全没问题;但在Firefox 下导入失败。跟踪Service 发现用Firefox 做导入请求时,该请求对象中未携带session信息导致的。查阅了API,没找到有效的解决办法。用IE和Firefox 做导入时,Service端取得的信息如下:
Solution: 在UI端做上传请求的URL中人为地添加sessionid信息。
var sessionId: String = ApplicationFacade.getInstance().currentUser.sessionId;
_url = _url.replace("?",";jsessionid=" + sessionId + "?");
Importer.as 类如下:
public class Importer { public static function upload(displayObj:displayObject,url:String):void { var _url:String = url; var parentObj:displayObject = displayObj; var file:FileReference =new FileReference(); openFile(); var pb:PopupProgressBar = PopUpManager.createPopUp(parentObj,PopupProgressBar,true) as PopupProgressBar; file.addEventListener(ProgressEvent.PROGRESS,onProgress); file.addEventListener(Event.SELECT,onSelect); file.addEventListener(Event.CANCEL,onCancel); file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadComplateHandler); file.addEventListener(IOErrorEvent.IO_ERROR,errorHandler); function uploadComplateHandler(event : DataEvent) : void { PopUpManager.removePopUp(pb); } function errorHandler(evt:IOErrorEvent):void { PopUpManager.removePopUp(pb); } function onCancel(evt:Event):void { PopUpManager.removePopUp(pb); } function onProgress(e:ProgressEvent):void { pb.importProgess(true); PopUpManager.centerPopUp(pb) } function openFile():void { file.browse([new FileFilter("File Type(*.csv)","*.csv;")]); } function onSelect(e:Event):void { proceedWithUpload(); } function proceedWithUpload():void { try { var sessionId: String = ApplicationFacade.getInstance().currentUser.sessionId; _url = _url.replace("?",";jsessionid=" + sessionId + "?"); var request:URLRequest = new URLRequest(_url); request.method = URLRequestMethod.POST; file.upload(request,"file"); } catch (error:Error) { PopUpManager.removePopUp(pb); Alert.show("upload Failed"); } } } }