From 2f43609ef63faf35e54fe5308acede77f99588d3 Mon Sep 17 00:00:00 2001 From: talent-tan Date: Sat, 5 Oct 2019 21:31:04 +0800 Subject: [PATCH] small modify --- .../freemarker/ShortMessageTemplateExceptionHandler.java | 4 ++-- .../org/tio/http/common/view/freemarker/FreemarkerConfig.java | 3 ++- .../tio/http/server/handler/DefaultHttpRequestHandler.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/src/main/java/org/tio/utils/freemarker/ShortMessageTemplateExceptionHandler.java b/src/utils/src/main/java/org/tio/utils/freemarker/ShortMessageTemplateExceptionHandler.java index a8d80bd1..edf699f0 100644 --- a/src/utils/src/main/java/org/tio/utils/freemarker/ShortMessageTemplateExceptionHandler.java +++ b/src/utils/src/main/java/org/tio/utils/freemarker/ShortMessageTemplateExceptionHandler.java @@ -209,8 +209,8 @@ recommend that a file or class name and description of purpose be included on * */ public class ShortMessageTemplateExceptionHandler implements TemplateExceptionHandler { - private static Logger log = LoggerFactory.getLogger(ShortMessageTemplateExceptionHandler.class); - public static ShortMessageTemplateExceptionHandler me = new ShortMessageTemplateExceptionHandler(); + private static Logger log = LoggerFactory.getLogger(ShortMessageTemplateExceptionHandler.class); + public final static ShortMessageTemplateExceptionHandler me = new ShortMessageTemplateExceptionHandler(); @Override public void handleTemplateException(TemplateException templateexception, Environment environment, Writer writer) throws TemplateException { diff --git a/src/zoo/http/common/src/main/java/org/tio/http/common/view/freemarker/FreemarkerConfig.java b/src/zoo/http/common/src/main/java/org/tio/http/common/view/freemarker/FreemarkerConfig.java index 81175e59..cbceb27a 100644 --- a/src/zoo/http/common/src/main/java/org/tio/http/common/view/freemarker/FreemarkerConfig.java +++ b/src/zoo/http/common/src/main/java/org/tio/http/common/view/freemarker/FreemarkerConfig.java @@ -288,13 +288,14 @@ private Configuration createConfiguration(HttpConfig httpConfig, String root) th } else { cfg.setDirectoryForTemplateLoading(new File(root)); } - cfg.setDefaultEncoding(httpConfig.getCharset()); // cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(false); cfg.setWrapUncheckedExceptions(true); cfg.setTemplateExceptionHandler(ShortMessageTemplateExceptionHandler.me); cfg.setLocale(Locale.SIMPLIFIED_CHINESE); + cfg.setNumberFormat("#"); + cfg.setClassicCompatible(true); return cfg; } diff --git a/src/zoo/http/server/src/main/java/org/tio/http/server/handler/DefaultHttpRequestHandler.java b/src/zoo/http/server/src/main/java/org/tio/http/server/handler/DefaultHttpRequestHandler.java index 93248002..8a442dad 100644 --- a/src/zoo/http/server/src/main/java/org/tio/http/server/handler/DefaultHttpRequestHandler.java +++ b/src/zoo/http/server/src/main/java/org/tio/http/server/handler/DefaultHttpRequestHandler.java @@ -822,7 +822,7 @@ public HttpResponse handler(HttpRequest request) throws Exception { String retStr = FreemarkerUtils.generateStringByPath(template, configuration, model); response = Resps.bytes(request, retStr.getBytes(configuration.getDefaultEncoding()), extension); return response; - } catch (Exception e) { + } catch (Throwable e) { log.error("freemarker错误,当成普通文本处理:" + file.getCanonicalPath() + ", " + e.toString()); } }