views:

113

answers:

1

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?

+1  A: 

There are a couple of possible failure points here.

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

  • 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

Instead 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.

McDowell