FreeMarker特殊字符输出为问号



我试图提交一个包含特殊字符字段的表单,例如€ŠšŽžŒœŸ。就我从ISO-8859-15维基百科页面上看到的,这些字符都包含在标准中。尽管请求和响应的编码都设置为ISO-8859-15,但当我试图显示这些值(在JAVA EE环境中使用FreeMarker 2.3.18)时,这些值是???????。我已经将表单的接受字符集设置为ISO-8859-15,我已经检查了表单是否以内容类型text/html;charset=ISO-8859-15(使用firebug)提交,但我不知道如何显示正确的字符。如果我运行下面的代码,正确的十六进制值显示为(ex: Ÿ = be)

我错过了什么?提前感谢!

System.out.println(Integer.toHexString(myString.charAt(i)));
编辑:

当我处理请求时,我有以下代码:

PrintStream ps = new PrintStream(System.out, true, "ISO-8859-15");
String firstName = request.getParameter("firstName");
// check for null before
for (int i = 0; i < firstName.length(); i++) {
     ps.println(firstName.charAt(i)); // prints "?"
}
BufferedWriter file=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "ISO-8859-15"));
file.write(firstName); // writes "?" to file (checked with notepad++, correct encoding set) 
file.close();

根据十六进制值,正确提交表单数据。问题似乎与产量有关。如果一个字符不能用当前字符集表示,Java将其替换为?

在构造输出流时必须使用正确的字符集。你会使用什么命令呢?我不知道FreeMarker,但可能会有像

这样的东西
Writer out = new OutputStreamWriter(System.out);

这个应该被替换成类似这样的内容:

Writer out = new OutputStreamWriter(System.out, "iso-8859-15");

顺便说一下,UTF-8通常是更好的编码字符集。

最新更新