? http://www.cnblogs.com/dannyr/archive/2004/11/24/68026.html 原文 情况: Flex默认使用的都是utf-8编码,包括Get,Post等方法。而Tomcat服务器端接收request对象默认是8859_1 编码,添加Tomcat的request Filter用request.setCharacterEncoding("utf-8"); 来设置,这个方法属于Tomcat设置和Flex无关,暂不讨论! flex?->Jsp: 有2种情况 //我试验第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接收后成功解释并正确显示。 |