0

I am working on an application that comprises of Hibernate, JPA, Spring.

I have a process that uses Freemarker to send emails at the end of the process.

The data in the free marker template is filled from database. The data has a £ pound symbol in the database but when freemarker processes it, It is convereted into ? symbol.

Code is as below

final StringWriter writer = new StringWriter();
Template template= freemarkerConfiguration.getTemplate("sampleReport.ftl");
template.process(this, writer);
System.out.println(writer.toString());

Printing the data retrieved from database , result is as below

INFO  05-22 10:08:18 Printing ?-- Hex :a3  

a3 - Is the hex code for pound symbol but its printing ? as well.

I cannot spot the error

Raedwald
  • 46,613
  • 43
  • 151
  • 237
Rishi
  • 224
  • 2
  • 3
  • 11
  • What's your terminal's encoding? Default system encoding? Etc. – Dave Newton May 21 '12 at 15:02
  • Linux system encoding = en_GB.UTF-8 – Rishi May 21 '12 at 15:05
  • I have tried setting the output encoding on the template but it does not work. – Rishi May 21 '12 at 16:28
  • It's going to be an encoding issue *somewhere* though, either in the terminal itself, the data retrieval, etc. because we've put I18N strings in FM templates with no issues. – Dave Newton May 21 '12 at 16:49
  • possible duplicate of [Display special characters using System.out.println](http://stackoverflow.com/questions/10933620/display-special-characters-using-system-out-println) – Raedwald Jun 19 '14 at 12:16

1 Answers1

0

FreeMarker works with UNICODE everywhere, so it doesn't generate ?-s itself. Print the character codes for that String rather than the String itself, and see if it already contains 0x3F (the UCS code of ?). If it doesn't, it's System.out.println that uses a wrong encoding, and so does whatever that encodes the e-mail for sending. If it does contain 0x3F, maybe something is messed up with JDBC there (again, you can check the String coming from JDBC by printing the character codes), so FreeMarker already receives ?.

ddekany
  • 29,656
  • 4
  • 57
  • 64