处理 UTF-8 DataString (Velocity/Struts)

发布于 2024-08-12 12:15:35 字数 400 浏览 6 评论 0原文

大家好,最近,我使用Struts和Velocity框架的组合创建了一些网站,问题是当我尝试输入UTF-8日文字符时,比如字段名称,我将其放入“索”值中,然后我单击提交(使用),数据将传递到 AddForm,其中我有字符串名称字段来处理名称字段。问题是,收到的字符串是一些奇怪的字母,而不是预期的字符串“索”,我将所有工作区设置为UTF-8,在velocity.property(input.coding/outputcoding = UTF-8),content-type/charset中= UTF-8,但它总是返回奇怪的字符串,我可以直接使用以下命令设置名称字段: public void setName(String name) { this.name = "索" } 和确认添加工作正常,但不能正常插入它添加表单上的名称字段,有人可以指出我出了什么问题吗?感谢您的耐心阅读:D。

Hey guys, lately, I use the combination of Struts and Velocity frameworks to create some website, the problem is that when I tried to input UTF-8 Japanese character, say, a field name, which I putted in the value of "索", then I click submit ( using ), the data would be passed to an AddForm, which I have the String name field to handle the name field. Problem is that, the received string is some strange letter than the expected string "索", I set all the workspace to UTF-8, in velocity.property ( input.coding/outputcoding = UTF-8 ), content-type/charset = UTF-8, but it always returns strange string, I could set the name field directly with : public void setName(String name) { this.name = "索" } and the confirm Add work fine, but not with normally insert it to name field on the addForm, someone could point me out what was wrong ? Thanks for patient reading :D.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半透明的墙 2024-08-19 12:15:35

我理解你的问题如下,是吗?

  • 您可以在客户端浏览器上正确发送并显示“索”,
  • 但是当表单发送回服务器时,数据已损坏。

这是由于:

  • 请求编码的编码(如您所说的 UTF-8)和
  • 服务器解码的编码(默认为 ISO-8859-1)之间不匹配引起的。

可以通过使用 Spring Framework 的 CharacterEncodingFilter 显式指定服务器端编码(上述第 2 个)来解决。

(注:Seasar和TERASOLUNA等日本框架有类似的过滤器和关于该问题的文章。)

I understood your problems is as follows, is this right?

  • you can send and display “索” correctly on client browsers,
  • but when the form is sent back to server, data is corrupted.

This is caused by mismatch between:

  • encoding in which the request is encoded (UTF-8 as you said) and
  • encoding by which the server decodes (ISO-8859-1 by default).

It can be solved by specifying server-side encoding (2nd of above) explicitly using CharacterEncodingFilter of Spring Framework.

(note: Japanese frameworks such as Seasar and TERASOLUNA have similar filter and articles on the problem.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文