index.jsp
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Locale" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: H
Date: 2019/7/23
Time: 11:19
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Index</title>
</head>
<body>
<%
request.setAttribute("date", new Date());
request.setAttribute("salary", 13541);
String code = request.getParameter("code");
if (code != null) {
if (code.equals("en")) {
session.setAttribute("Local", Locale.US);
} else if (code.equals("zh")) {
session.setAttribute("Local", Locale.CHINA);
}
}
%>
<c:if test="${Local!=null}">
<fmt:setLocale value="${sessionScope.Local}"></fmt:setLocale>
</c:if><fmt:setBundle basename="i18n"></fmt:setBundle>
<fmt:message key="date"></fmt:message>
<fmt:formatDate value="${date}" dateStyle="FULL"></fmt:formatDate>
<br>
<fmt:message key="salary"></fmt:message>
<fmt:formatNumber value="${salary}" type="currency"></fmt:formatNumber>
<br>
<a href="index.jsp?code=en">英文</a>
<a href="index.jsp?code=zh">中文</a>
</body>
</html>
根据不同的国家配置不同的i18n
src目录下
i18n_en_US.properties:英语
date=Date
salary=salary
i18n_zh_CN.properties:汉语
date=\u65e5\u671f
salary=\u5de5\u8d44
日期对应的ASCII:\u65e5\u671f
命令行中文转ASCII(已配置好jdk)
效果展示
点击英文
点击中文