关于JAVA Post中的字符代码转换
日元标记用以下两种方式表示
- 0x5c (ASCII)
- 0xa5 (utf-8)
当我在Java6、Struts2的环境中进行0xA5的POST时,在日志中输出的阶段,我变成0x5C。
具体在哪里进行字符代码的替换呢?
Japanese Yen Mark is expressed with two ways of next
- 0x5c (ASCII)
- 0xa5 (utf-8)
When I did a POST of 0xA5 in Java6, environment of Struts2, at the stage that I output in log, I become 0x5C.
Where will substitution of a character code be performed to be concrete?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题不在于字符转换,而在于错误转换或损坏。 字符 5C 在 ASCII 中是“\”。 对我来说,什么错误转换会将 A5 变成 5C 并不是很明显。 日元符号之前或之后的其他字符是否也被错误转换?
开始查找问题原因的前两个位置是代码从 String 转换为 byte[] 并再次转换回来的位置。 在客户端转换 POST 数据时,应确保设置在 HTTP 请求 Content-Type 标头中使用的字符集。 然后在服务器端,确保您的代码使用传入请求的 Content-Type 标头中指定的字符集。
I think that the problem is not character conversion but misconversion or corruption. The character 5C in ASCII is '\'. It is not immediately obvious to me what misconversion would turn A5 into 5C. Are other characters before or after the Yen symbol misconverted as well?
The first two places to start looking for the cause of the problem would be where your code converts from String to byte[] and back again. When converting the POST data on the client side you should make sure that you set the charset that you use in the HTTP request Content-Type header. Then on the server side, make sure that your code uses the charset specified in the incoming request's Content-Type header.
我相信您在问日元符号何时会变成 ASCII - 答案是当底层默认字符编码从 UTF-8 更改为 ASCII 时。 这可能发生在很多地方:
您能否提供更多关于您当前设置的信息?
I believe you're asking when it the Yen symbol will become ASCII - the answer is when the underlying default character encoding changes from UTF-8 to ASCII. This could happen in a number of places:
Can you provide some more information on what you currently have set for these?