gpt4 book ai didi

java - UTF-8编码和http参数

转载 作者:搜寻专家 更新时间:2023-10-31 19:42:02 25 4
gpt4 key购买 nike

我正在使用 YahooUI Javascript 库进行简单的 ajax 调用,如下所示:

YAHOO.util.Connect.setForm('myform');
YAHOO.util.Connect.asyncRequest('POST', url, ...);

以下是我的应用程序中的设置:Tomcat版本:6.0.18

Tomcat 服务器连接器:URIEncoding="UTF-8"网络应用页面:

在 YahooUI 连接器库文档中也有说明:

setForm will encode each HTML form field's name and value using encodeURIComponent. This results in a string of UTF-8 encoded, name-value pairs. NOTE: Setting an HTTP header of "Content-Type" with a different charset value will not change the encoding of the serialized data.encoding of the serialized data.

我可以看到作为参数发送的法语字符已编码(在 ie7 中使用 iehttpheader 工具):

    name=%C3%88%C3%A0%C3%B4 
testParam=%C3%B4%C3%B4

对于数据:名称: Èàô和 testParam: ôô

但在服务器端,我看到的值如下:Ø Ø Ø

即使我将字符串转换为字节,然后使用如下定义的字符集创建新字符串: String val = new String(oo.getBytes("UTF-8"));我无法获得预期的准确数据。

注意:我已引用以下问题,但无法解决此问题:How to get UTF-8 working in Java webapps?请指导。

更新:调用 W3.org 网站上给出的解码 UTF-8 函数 http://www.w3.org/International/O-URL-code.html给了我预期的结果。我希望 Tomcat 能够对此进行解码?

最佳答案

由于您使用的是 POST 查询,因此 URIEncoding="UTF-8" 不适用于此处。你需要设置一个过滤器来告诉Tomcat你的请求编码是UTF-8。例如,您可以使用 Spring 的 CharacterEncodingFilter(usagejavadoc)。还可以找到此类过滤器的其他实现。

关于java - UTF-8编码和http参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3665682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com