国际化

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
i18n_en_US.properties:英语

date=Date
salary=salary

i18n_zh_CN.properties:汉语

date=\u65e5\u671f
salary=\u5de5\u8d44

日期对应的ASCII:\u65e5\u671f

命令行中文转ASCII(已配置好jdk)
在这里插入图片描述

在这里插入图片描述
效果展示
在这里插入图片描述
点击英文
在这里插入图片描述
点击中文
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值