如何使用 Spring/Roo 对 POST 的特殊字符进行编码
我正在使用 Spring/Roo 作为应用程序服务器,并且需要能够发布一些特殊字符。具体来说,是日元符号或欧元符号等字符。当我在服务器上收到这些字符并将它们显示在控制台中时,它们显示为“?”。如何正确编码和接收它们?
I'm using Spring/Roo for an app server, and need to be able to post some special characters. Specifically, characters like the Yen symbol, or Euro symbol. When I receive these characters on my server, and display them in console, they appear as "?". How can they be properly encoded and received?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 src/main/resources/META-INF/spring/database.properties 配置为:
Try configuring
src/main/resources/META-INF/spring/database.properties
to this :这里有几个可能的故障点。
首先,我会检查控制台是否支持有问题的字符:
System.out
会将它们转换为问号,System.out
编码不同的编码来解码字节,则这些字符将无法正确显示不要尝试将字符打印为文字,而是转换为
int
并打印十六进制值 - 然后根据 Unicode 图表。浏览器和服务器之间也可能发生有损或不正确的转换。理想情况下,服务器应该使用 UTF-8 进行编码和解码。如果浏览器在对数据进行编码时使用的编码不支持这些字符,则会对它们进行有损编码;浏览器通常根据服务器为 GET 请求发送的编码来选择编码(或者更罕见地从 表单属性)。检查与您的数据一起发送的
Accept-Charset
标头(您可以使用 Firebug 或 Fiddler)。我对 Roo 一无所知,但肯定有某种配置编码的机制。There are a couple of possible failure points here.
First, I'd check to see if the console supports the characters in question:
System.out
System.out
is encoding them to, the characters will not display correctlyInstead of trying to print characters as literal, cast to
int
and print the hex value - then check the value against the Unicode charts.Lossy or incorrect conversions can also happen between the browser and the server. Ideally, the server should use UTF-8 for encoding and decoding. If the encoding used by the browser when it encodes the data does not support the characters, they will be lossily encoded; the browser usually picks an encoding based on the encoding sent by the server for the GET request (or more rarely from a form attribute). Inspect the
Accept-Charset
header being sent with your data (you can do this with something like Firebug or Fiddler). I don't know anything about Roo, but there's bound to be some mechanism to configure encodings.