flex httpservice与java通讯的中文乱码解决。

利用url方式传中文参数,需要进行url编码才行,比较麻烦。

利用form方式传中文参数,不需要进行编码,比较简单。只需要注意两点即可:

1、flex默认编码是utf-8,因此java后台设置对request的解码也为utf-8,即可获得中文,不用管tomcat中间服务器的编码是什么。

2、flex中httpservice的send方式不同,url方式为dbsvc1.request.type="cmd";  form方式为:dbsvc1.send(参数对象...),flex自动会把object对象转为form形式进行提交,具体如下:

                    //dbsvc1.request.type="cmd";

                    //dbsvc1.request.sql=_sql;
                    var oo:Object=new Object();  //!!!必须以form形式提交,否则url方式中文无法正确接收,需要编码
                    oo.type="cmd";
                    oo.sql=_sql;

                    dbsvc1.send(oo);  //flex默认编码是utf-8,只要java后台设置request的解码,即可获得中文,不用管tomcat中间服务器的编码是什么。


java后台:

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");  //设置request解码为utf-8,flex前台默认也是utf-8
        Tdb db=new Tdb();
        db.init_dbcfg(request);
        String format=request.getParameter("format")==null?"":request.getParameter("format").toString();
        String type=request.getParameter("type")==null?"":request.getParameter("type").toString();
      。。。。。

        response.setCharacterEncoding("UTF-8");
        response.getWriter().print(data); 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值