flex中HTTPService乱码解决
日期:2009-01-19 阅读:244 分类:Flex~Flash
1.在使用HTTPService传送数据带中文时出现乱码,如果解决呢?
//参数进行UTF-8的编码处理
private function httpEncoding(param:String):String{
return encodeURIComponent(param); //encodeURI(param)
}
public function sendRequest(locale:String):void{
var httpService:HTTPService=new HTTPService();
httpService.resultFormat="text";
httpService.url="servlet/TestServlet";
//使用URLVariables动态对象传输设置参数
var params:URLVariables=new URLVariables();
params.locale=httpEncoding(locale);//中文编码处理
var responder:Responder=new Responder(onSuccess,onFault);
var call:AsyncToken=httpService.send(params);
call.addResponder(responder);
}
2.在后台接收参数进行解码(Java版).
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String locale = URLDecoder.decode(request.getParameter("locale"),
"utf-8");
out.println(locale);
out.flush();
out.close();
}
//参数进行UTF-8的编码处理
private function httpEncoding(param:String):String{
return encodeURIComponent(param); //encodeURI(param)
}
public function sendRequest(locale:String):void{
var httpService:HTTPService=new HTTPService();
httpService.resultFormat="text";
httpService.url="servlet/TestServlet";
//使用URLVariables动态对象传输设置参数
var params:URLVariables=new URLVariables();
params.locale=httpEncoding(locale);//中文编码处理
var responder:Responder=new Responder(onSuccess,onFault);
var call:AsyncToken=httpService.send(params);
call.addResponder(responder);
}
2.在后台接收参数进行解码(Java版).
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String locale = URLDecoder.decode(request.getParameter("locale"),
"utf-8");
out.println(locale);
out.flush();
out.close();
}
本页链接: http://www.scriptlover.com/static/327-flex-HTTPService-乱码
标签: flex HTTPService 乱码
相关文章
- 在Flex中使用CSS 2008-12-18
- Flex添加事件监听 2008-12-18
- Flex编码的过程分析 2008-12-22
- 不错的flex资料站点 2008-11-02
- Flex简单开发环境 2008-11-01
- 解决Linux中文乱码问题 2011-12-03
- ASP+AJAX参数汉字/中文乱码 2011-09-11