错误信息页面国际化修正

Signed-off-by: zhangwei <zhangwei2@iie.ac.cn>
This commit is contained in:
zhangwei
2018-11-02 10:40:53 +08:00
parent 41ec530356
commit ae191e4a41
4 changed files with 75 additions and 7 deletions

View File

@@ -3,9 +3,23 @@ response.setStatus(400);
// 获取异常类
Throwable ex = Exceptions.getThrowable(request);
//获取国际化信息
Properties msgProp = new Properties();
try {
String language = LocaleContextHolder.getLocale().getLanguage();
if (language.equals("zh_cn") || language.equals("zh")) {
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_zh_CN.properties"));
} else if (language.equals("ru")) {
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_ru.properties"));
} else {
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_en.properties"));
}
} catch (Exception e) {
msgProp = null;
}
// 编译错误信息
StringBuilder sb = new StringBuilder("(400)<spring:message code=\"exception_info\"/>\n");
StringBuilder sb = new StringBuilder("(400)"+msgProp!=null?msgProp.getProperty("exception_info"):"Exception Infomation"+":\n");
if (ex != null) {
if (ex instanceof BindException) {
for (ObjectError e : ((BindException)ex).getGlobalErrors()){
@@ -24,7 +38,7 @@ if (ex != null) {
sb.append("☆" + ex.getMessage());
}
} else {
sb.append("<spring:message code=\"unkown_error\"/>.\n\n");
sb.append(msgProp!=null?msgProp.getProperty("unkown_error"):"Unkown Error Infomation"+":\n\n");
}
// 如果是异步请求或是手机端,则直接返回信息
@@ -42,6 +56,9 @@ else {
<%@page import="com.nis.web.security.Servlets"%>
<%@page import="com.nis.util.Exceptions"%>
<%@page import="com.nis.util.StringUtils"%>
<%@page import="java.util.Properties"%>
<%@page import="org.springframework.context.i18n.LocaleContextHolder"%>
<%@page import="com.nis.util.Configurations"%>
<%@page contentType="text/html;charset=UTF-8" isErrorPage="true"%>
<%@include file="/WEB-INF/include/taglib.jsp"%>
<!DOCTYPE html>