码迷,mamicode.com
首页 > Web开发 > 详细

flex   HTTPService 封装以及 中文乱码

时间:2015-04-07 19:59:07      阅读:216      评论:0      收藏:0      [点我收藏+]

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


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

flex   HTTPService 封装以及 中文乱码

标签:flex httpservice 封装 中文乱码

原文地址:http://6902447.blog.51cto.com/6892447/1629696

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!