package com.boco.eoms.flex.service
{
import com.boco.eoms.flex.service.components.LoadingMask;
public class RequestServer
{
import flash.net.URLVariables;
import mx.controls.Alert;
import mx.rpc.http.HTTPService;
private var service:HTTPService;
public function RequestServer()
{
super();
}
private function init(fn:Function,faultFn:Function):void{
if(this.service == null){
service=new HTTPService();
service.method="POST";
service.useProxy=false;
service.resultFormat=HTTPService.RESULT_FORMAT_XML;
service.addEventListener("result", fn);
service.addEventListener("fault", faultFn);
}
}
/**
* 調用服務器
*/
public function queryChartPage(ip:String,port:String,path:String,
monitorType:String,selectCity:String,selectCityId:String,
selectIndicator:String,selectIndicatorId:String,selectChart:String,
fn:Function,faultFn:Function):void{
LoadingMask.show();
var url:String = "http://"+ip+":"+port+path+"/eomsSheetMonitorThreeController/queryChartPage.do";
//Alert.show(url);
this.init(fn,faultFn);//初始化httpService
service.url=url;
var params:URLVariables = new URLVariables();
//params.method = "monitorView";
params.monitorType = monitorType;
params.selectCity = httpEncoding(selectCity);
params.selectCityId = httpEncoding(selectCityId);
params.selectIndicator = httpEncoding(selectIndicator);
params.selectIndicatorId=httpEncoding(selectIndicatorId);
params.selectChart = httpEncoding(selectChart);
service.send(params);
}
//對提交給後臺的參數進行UTF-8的編碼處理
private function httpEncoding(param:String):String{
return encodeURIComponent(param);
}
}
java後臺代碼接收參數
//處理post方式亂碼
request.setCharacterEncoding("utf-8");
String selectCity=URLDecoder.decode(request.getParameter("selectCity"),"utf-8");//選中的地市名
String selectCityId=URLDecoder.decode(request.getParameter("selectCityId"),"utf-8");//選中的地市ID
String selectIndicator=URLDecoder.decode(request.getParameter("selectIndicator"),"utf-8");//選中的指標名
String selectIndicatorId=URLDecoder.decode(request.getParameter("selectIndicatorId"),"utf-8");//選中的指標ID
String selectChart=URLDecoder.decode(request.getParameter("selectChart"),"utf-8");//選中的圖形