处理 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 = "索" } 和确认添加工作正常,但不能正常插入它添加表单上的名称字段,有人可以指出我出了什么问题吗?感谢您的耐心阅读: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我理解你的问题如下,是吗?
这是由于:
可以通过使用 Spring Framework 的
CharacterEncodingFilter
显式指定服务器端编码(上述第 2 个)来解决。(注:Seasar和TERASOLUNA等日本框架有类似的过滤器和关于该问题的文章。)
I understood your problems is as follows, is this right?
This is caused by mismatch between:
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.)