如何使用Spring / Roo对POST进行特殊字符编码 [英] How to encode special characters for a POST with Spring/Roo

查看:202
本文介绍了如何使用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?

推荐答案

这里有几个可能的失败点。

There are a couple of possible failure points here.

首先,我会检查控制台是否支持有问题的字符:

First, I'd check to see if the console supports the characters in question:


  • 如果JVM使用的默认编码不支持字符,它们将被转换成问号,由 System.out

  • 如果控制台字体不支持字符,如果控制台使用不同的编码解码字节,那么它们将不会被正确地呈现

  • System.out 正在编码它们,字符将无法正确显示

  • if the default encoding used by the JVM does not support the characters, they will be turned into question marks by System.out
  • if the console font does not support the characters, they will not be rendered properly
  • if the console is decoding the bytes using a different encoding to the one System.out is encoding them to, the characters will not display correctly

而不是尝试将字符打印为文字, code> int 并打印十六进制值 - 然后根据 Unicode图表检查值

Instead of trying to print characters as literal, cast to int and print the hex value - then check the value against the Unicode charts.

有损或不正确的转换也可以h在浏览器和服务器之间。理想情况下,服务器应该使用UTF-8进行编码和解码。如果浏览器在编码数据时使用的编码不支持字符,则它们将被有损编码;浏览器通常会根据服务器为GET请求发送的编码选择一个编码(或更罕见的是从表单属性)。检查 Accept-Charset 标题与您的数据一起发送(您可以使用 Firebug Fiddler )。我不知道Roo什么,但是一定要有一些配置编码的机制。

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.

这篇关于如何使用Spring / Roo对POST进行特殊字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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