如何使IE在UTF-8中发布FORM数据? [英] How to make IE post FORM data in UTF-8?
问题描述
这是以下问题的延续: Java泽西:接收表单参数作为字节数组
即使包含页面使用ISO-8859-1字符集,我需要将表单数据发布在UTF-8中。我找到一个FF的解决方案,但不是为IE。
这是整个故事:
我使用Jersey REST Web服务来接收从简单的html< FORM>发布的数据。
当页面使用UTF-8字符集时,发布的数据也使用UTF-8进行编码,一切正常。
但是当页面使用ISO-8859-1字符集时,FORM数据也使用ISO-8859-1发布,泽西有特殊字符的麻烦(可能是因为它预期数据进入UTF-8)。
@Path(/ someMethod )
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String someMethod(@FormParam(someParam)String someParam)
{
...
}
当然如果我改变整个页面编码为UTF-8,一切正常,问题是我将表单动态添加到可能使用不同编码的现有页面(在其他工作中,我无法篡改页面编码)。
我有解决方案适用于FF但不适用于IE。如果我向发送数据的FORM添加了 accept-charset =utf-8
属性,则FF使用utf-8对所有发布的数据进行正确编码,而不管包含页面编码,但是这在IE中不起作用。
任何想法?
谢谢!
Ruby on rails应用程序使用这个技巧:它们在隐藏的字段中添加了一个UTF-8不能强制进入ISO拉丁语1的字符。
他们使用的字段是
< input name =utf8type =hiddenvalue =&#x2713; />
,最终在查询参数中为
search?param1 = foo& param2 = bar& utf8 =✓
历史记录:在 utf8 =✓
之前,Ruby on rails使用了一个花哨的雪人强制UTF-8: http://intertwingly.net/blog/2010/07/29/Rails-and-Snowmen 。
This is continuation of this question: Java Jersey: Receive form parameter as byte array
I need form data to be posted in UTF-8 even if containing page uses ISO-8859-1 charset. I found a solution for FF, but not for IE. Here is the whole story:
I use Jersey REST web service to receive data posted from simple html <FORM>. When the page uses UTF-8 charset, posted data is also encoded using UTF-8 and everything works fine. But when the page uses ISO-8859-1 charset, FORM data is also posted using ISO-8859-1 and Jersey has trouble with special characters (probably because it expects data to come in UTF-8).
Jersey method looks like this:
@Path("/someMethod")
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String someMethod(@FormParam("someParam") String someParam)
{
...
}
Of course if I change the whole page encoding to UTF-8, everything works fine, the problem is that I add form dynamically to existing pages that may use different encoding (in other works I can't tamper with page encoding).
I have solution that works for FF but not for IE. If I add accept-charset="utf-8"
attribute to FORM that posts the data, FF correctly encodes all posted data using utf-8 regardless of containing page encoding, but this doesn't work in IE.
Any ideas? Thank you!
Ruby on rails applications use this trick: they add in an hidden field an UTF-8 character that cannot be coerced into ISO Latin 1.
The field they use is
<input name="utf8" type="hidden" value="✓" />
and it ends up in the query parameters as
search?param1=foo¶m2=bar&utf8=✓
History note: before utf8=✓
, Ruby on rails used a fancy snowman to force UTF-8: http://intertwingly.net/blog/2010/07/29/Rails-and-Snowmen.
这篇关于如何使IE在UTF-8中发布FORM数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!