如何让IE浏览器后表单数据以UTF-8? [英] How to make IE post FORM data in UTF-8?

查看:416
本文介绍了如何让IE浏览器后表单数据以UTF-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这个问题的延续:<一href=\"http://stackoverflow.com/questions/6282626/java-jersey-receive-form-parameter-as-byte-array\">Java球衣号码:接收​​的形式参数作为字节数组

This is continuation of this question: Java Jersey: Receive form parameter as byte array

我需要UTF-8被张贴形式的数据,即使页面包含使用ISO-8859-1字符集。我找到了FF的解决方案,而不是IE浏览器。
这里是整个故事:

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:

我使用REST新泽西Web服务来接收从简单的HTML和LT发布的数据,表格取代。
当页面使用UTF-8字符集,发布的数据也连接使用UTF-8 codeD,一切工作正常。
但是,当页面使用ISO-8859-1字符集,表单数据还使用ISO-8859-1发布和泽西岛有特殊字符的麻烦(可能是因为它预计数据进来UTF-8)。

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).

泽西方法是这样的:

@Path("/someMethod")
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String someMethod(@FormParam("someParam") String someParam)
{
    ...
}

当然,如果我改变整个页面编码为UTF-8,一切工作正常,问题是,我动态添加的形式,可能会使用不同的编码(其他作品,我不能跟页面编码篡改)现有页面

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).

我的解决方案,为FF,但不是IE的作品。如果我添加接收字符集=utf-8属性,形成岗位数据,FF正确连接codeS全部采用发布的数据UTF-8,无论含页面编码,但这并不在IE浏览器。

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应用使用这一招:他们在一个隐藏字段添加不能强迫ISO拉丁文的UTF-8字符1

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.

他们使用的字段是

<input name="utf8" type="hidden" value="&#x2713;" />

和它在查询参数

search?param1=foo&param2=bar&utf8=✓

历史记:之前 = UTF8✓,轨道上的Ruby使用花哨的雪人强制UTF-8:的 http://intertwingly.net/blog/2010/07/29/Rails-and-Snowmen

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆