У меня есть проект, который использует сервер причала, который использует freemarker. Я использую русские буквы в своих шаблонах и получаю ?
. Все предметы, которые я прочитал раньше, не помогли мне. я использую в своем кодеОшибочное кодирование Freemarker
.setContentType("text/html;charset=utf-8");
.setCharacterEncoding("UTF-8");
все мои файлы в UTF-8.
Мои Freemarker страница Genertor сервлет
public class PageGenerator {
private static PageGenerator pageGenerator;
private Configuration cfg;
public static PageGenerator instance() {
if (pageGenerator == null)
pageGenerator = new PageGenerator();
return pageGenerator;
}
public String getPage(String filename, Map<String, Object> data) {
Writer stream = new StringWriter();
try {
Template template = cfg.getTemplate(filename);
template.process(data, stream);
} catch (IOException | TemplateException e) {
e.printStackTrace();
}
return stream.toString();
}
private PageGenerator() {
cfg = setCfg();
}
private Configuration setCfg(){
cfg = new Configuration(Configuration.VERSION_2_3_20);
try {
cfg.setDirectoryForTemplateLoading(new File("templates/"));
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
} catch (IOException e) {
e.printStackTrace();
}
return cfg;
}
}
Но Brouser моя страница в Windows-1252 кодировке.
Является '?' -s уже присутствует в результате 'stream.toString()', если вы посмотрите на него прямо там с отладчиком или таким (не в браузере)? – ddekany