处理 UTF-8 DataString ( Velocity/Struts ) [英] Handle UTF-8 DataString ( Velocity/Struts )

查看:24
本文介绍了处理 UTF-8 DataString ( Velocity/Struts )的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,最近我用 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 = "索" } 和确认添加工作正常,但不能正常插入要在 addForm 上命名字段,有人可以指出我出了什么问题吗?感谢耐心阅读: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.

推荐答案

我了解到您的问题如下,是这样吗?

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

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

这是由以下之间的不匹配引起的:

This is caused by mismatch between:

  • 编码请求的编码(如您所说的UTF-8)和
  • 服务器解码的编码(默认为 ISO-8859-1).

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

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

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

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

这篇关于处理 UTF-8 DataString ( Velocity/Struts )的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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