flex HTTPService 封装以及 中文乱码

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");//选中的图形


本文出自 “我的地盘” 博客,谢绝转载!

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。