情况:
Flex默认使用的都是utf-8编码,包括Get,Post等方法。而Tomcat服务器端接收request对象默认是8859_1编码,添加Tomcat的request Filter用request.setCharacterEncoding("utf-8"); 来设置,这个方法属于Tomcat设置和Flex无关,暂不讨论!

flex->Jsp:
有2种情况
情况一、MXML源代码文件中写入的中文字符:
Flex使用 System.useCodepage = true;即使用本地操作系统编码(GBK) 设置Flex的处理编码。Jsp中用依然用ISO_8859_1编码来处理,并转化为GBK。这样Jsp可以正确解释Flex传递的中文字符。 这个时候可以认为Flex对mxml源代码文件进行编译时候,源代码中的中文字符已经混乱了,所以要加上System.useCodepage = true;语句,按GBK编码将中文字符从Flex发送到Tomcat。
同时Tomcat中Jsp应该按GBK重新编码
String categoryID = request.getParameter("categoryID");
String strOut = new String(categoryID.getBytes("ISO8859-1"), "GBK");
System.out.println("categoryID="+categoryID);
System.out.println("categoryID="+strOut);

情况二、Flex运行时候由输入框输入的中文字符
这个时候输入框输入的中文字符是一定为UTF-8编码的,所以Flex中System.useCodepage = false;或者不设置,就默认utf-8编码格式传递数据,而Tomcat中Jsp使用下面语句按UTF-8来重新编码
String categoryID = request.getParameter("categoryID");
String strOut = new String(categoryID.getBytes("ISO8859-1"), "utf-8");
System.out.println("categoryID="+categoryID);
System.out.println("categoryID="+strOut);

Jsp->Flex:
Jsp页面用页面指令<%@ page contentType="text/html;charset=utf-8"%>设置,返回结果是utf-8编码,Flex接收后成功解释并正确显示。

测试环境:
Windows2000 Server    (字符集为GBK)
Tomcat 5.0.28    (默认设置)
JDK1.5.0 flex 1.5    (默认设置)
SqlServer2000 Sp3

测试代码:仅仅为第二种情况,第一种情况酌情修改即可
表结构
其中categoryid使用中文内容

create table tblMobile (id int, name varchar(20), price decimal(10,2), image varchar(50), categoryid varchar(20))

phonelist.jsp
这里数据库连接是SqlServer2000

<?xml version="1.0" encoding="utf-8"?>
<%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.sql.*"%>
<phonelist>
<%
    String sql = "";
    String url = "";

    String categoryID = request.getParameter("categoryID");

    try {
        Class .Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
        url = "jdbc:microsoft:sqlserver://myserver:1433;DatabaseName=flex;User=flex;Password=flex;";
        Connection conn = DriverManager.getConnection(url);
        Statement stmt = conn.createStatement();

        
        String strOut = new String(categoryID.getBytes("ISO8859-1"), "GBK"); 

        System.out.println("categoryID="+categoryID);
        System.out.println("categoryID="+strOut);

        sql = "select id, name, price, image from tblMobile where categoryid='" + strOut + "'";
        ResultSet rs = stmt.executeQuery(sql);

        while (rs.next()){
            out.println("<phone id=\"" + rs.getString(1) + "\">");
            out.println("<id>" + rs.getString(1) + "</id>");
            out.println("<name>" + rs.getString(2) + "</name>");
            out.println("<price>" + rs.getString(3) + "</price>");
            out.println("<image>" + rs.getString(4) + "</image>");
            out.println("</phone>");
        }

        rs.close();
        stmt.close();
        conn.close();

    } catch (Exception e) {
        out.println(e);
    }
%>
</phonelist>

test.mxml
其中HTTPService使用自定义request对象传递数据,注意前面的System.useCodepage = true;语句

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
    verticalGap="10"
    backgroundColor="#FFFFFF"
    pageTitle="手机"
    initialize="initApp()">
    
    <mx:HTTPService id="phoneService" url="phonelist.jsp" fault="alert(event.fault.faultstring)"/>

    <mx:Model id="phonelist">
        {phoneService.result.phonelist.phone}
    </mx:Model>


    <mx:Script>
        <![CDATA[

        var categoryId = 1;
        var categoryName = "Moto";
    
        function initApp() {
            System.useCodepage = true;
            categoryId = "目录1";
            var obj = new Object();
            obj["categoryID"] = categoryId;
            phoneService.send(obj);
        }

        ]]>
    </mx:Script>

    <mx:HBox>
        <mx:LinkBar styleName="title" width="500" click="" >
            <mx:dataProvider>
                <mx:Array>
                    <mx:Object label="首 页" link="main"/>
                    <mx:Object label="手机分类" link="catagory"/>
                    <mx:Object label="论 坛" link="forum"/>
                    <mx:Object label="关 于" link="about"/>
                </mx:Array>
            </mx:dataProvider>
        </mx:LinkBar>
        <mx:Label text="搜索"/>
        <mx:TextInput id="key" width="120"/>
        <mx:Button label="Go" click="initApp();"/>
    </mx:HBox>
    
    <mx:DataGrid dataProvider="{phonelist}">
        <mx:columns>
            <mx:Array>
                <mx:DataGridColumn columnName="id" headerText="ID"/>
                <mx:DataGridColumn columnName="name"  headerText="Name"/>
                <mx:DataGridColumn columnName="image"  headerText="Image"/>
            </mx:Array>
        </mx:columns>
    </mx:DataGrid>

    <mx:HBox horizontalAlign="center">
        <mx:Label text="Copy Right 2004  dannyr's Studio "/>
    </mx:HBox>
</mx:Application>

结果:
在Jsp页面里按8859_1编码可以成功获取Flex传递的中文内容。

备注:
这个方法是对Tomcat的,其他的Java应用服务器的Request处理方式可能不同,应区分对待!

引用:
以下是Flex文档关于System.useCodepage的说明:(比较简单,就不翻译了)

System.useCodepage

Availability

flash Player 6.

Usage

System.useCodepage:Boolean

Description

Property; a Boolean value that tells flash Player whether to use Unicode or the traditional code page of the operating system running the player to interpret external text files. The default value of System.useCodepage is false.

关于上个Flex-Jsp-DB例子中Flex和Jsp传递中文参数问题的解决方法!(Tomcat服务器)...相关推荐

  1. jquery.ajax的url中传递中文乱码问题的解决方法

    jquery.ajax的url中传递中文乱码问题的解决方法 JQuery JQuery默认的contentType:application/x-www-form-urlencoded 这才是JQuer ...

  2. eclipse中生成的html存在中文乱码问题的解决方法

    eclipse中生成的html存在中文乱码问题的解决方法 参考文章: (1)eclipse中生成的html存在中文乱码问题的解决方法 (2)https://www.cnblogs.com/bug-hu ...

  3. Js的Url中传递中文参数乱码的解决

    一:Js的Url中传递中文参数乱码问题,重点:encodeURI编码,decodeURI解码: 1.传参页面 Javascript代码: 2. 接收参数页面:test02.html 二:如何获取Url ...

  4. ppt上显示无法显示图片计算机可能,打不开电脑中的ppt文件并提示访问出错的解决方法...

    ‍ 有一位用户在网上下载了一些ppt文件,但当打开这些ppt文件时,却弹出一个窗口显示内容有问题,可尝试修复此演示文稿.但是当点击修复后又出现了访问出错的提示.对于以上出现的问题,导致无法打开电脑中的 ...

  5. 【已解决】对JSP页面传值中文乱码的简单解决方法

    很多java程序员在日常的工作中总会遇到对JSP页面传值中文乱码的情况,一些朋友由于操作不当,造成了很大的麻烦.本文将为大家讲解关于对JSP页面传值中文乱码的简单解决方法的内容. 方法/步骤 方法一: ...

  6. JSP页面之间传递中文参数的解决方法

    本文转载自: 关于JSP页面之间传值的中文乱码总结 用过滤器来解决JSP中文乱码问题 URLEncoder.encode与URLDecoder.docode传递中文参数编码与解码 URLEncoder ...

  7. hp打印机无法与计算机,电脑中安装HP打印机后重启无法打印的解决方法

    电脑中安装HP打印机后重启无法打印怎么办?近来不少朋友都向小编咨询了这个问题.HP有一个型号重启以后无法打印,今天系统城小编就要在这里给大家介绍一个方法可以解决这个问题. 具体方法如下: 1.这是第一 ...

  8. C# .net中cookie值为中文时的乱码解决方法

    C# .net中cookie值为中文时的乱码解决方法 一.cookie的名称或子cookie的名称不能为中文,否则无法获得cookie 这个好办,名称不用中文即可 二.cookie的值为中文时候,取c ...

  9. 扫描仪图标无法显示计算机,win7“我的电脑”中不显示扫描仪和摄像头的原因和解决方法...

    安装win7旗舰版系统后,点击打开"我的电脑"发现不显示扫描仪和摄像头图标,那么扫描仪和摄像头去哪里了呢?起初以为驱动没装好,但经过仔细研究,终于找到win7"我的电脑& ...

最新文章

  1. [译]React Component最佳实践
  2. 哈希表的C实现(二)
  3. nrf51822-配对绑定实现过程
  4. RPAD()和LPAD()函数进行字符串的填充
  5. (转)TDI FILTER 网络过滤驱动完全解析
  6. 个性化推荐系统原理介绍(基于内容推荐/协同过滤/关联规则/序列模式/基于社交推荐)...
  7. 【HDU - 1285】确定比赛名次 (拓扑排序)
  8. python的六个类型_介绍Python中6个序列的内置类型
  9. EJB - 无状态SessionBean简单示例
  10. 2021-08-27 BERT4Rec简介
  11. 密码字典生成工具:crunch
  12. 微信小程序-引入iconfont图标
  13. XPS文件怎么转成Word呢
  14. LabWindows/CVI入门之第二章:GUI开发
  15. 独立主机配置FTP,解析域名经历
  16. OCR识别新能源车牌的原理
  17. HDU 6405 Make ZYB Happy 后缀自动机 前缀和优化
  18. SNS运营之Tumblr迅速涨粉的20个方法-适用于海外社媒推广,外贸独立站,自建站,让你粉丝快速翻倍
  19. Codeforces Round #322 B Luxurious Houses
  20. 关于找到pycharm中jetbrains-agent更新的打开路径的方法

热门文章

  1. onethink不能安装到已经存在的数据库中的问题
  2. 【.Net Micro Framework PortingKit - 03】调试初步:点亮LED灯
  3. JavaScript中避免Form重复提交的两种方案
  4. python json模块的内部实现_python – 如何使用JSON模块进行漂亮打印时实现自定义缩进?...
  5. gbdt 回归 特征重要性 排序_RandomForest、GBDT、XGBoost、lightGBM 原理与区别
  6. Linux 操作系统原理 — Namespace 资源隔离
  7. Go 语言编程 — 使用 delve 进行 DEBUG 调试
  8. Linux 操作系统原理 — 系统结构
  9. 我脑中飘来飘去的css魔幻属性
  10. 深入Java核心 Java中多态的实现机制(1)