i18n国际化(看我的就够了)

版权声明:转载请指明出处 https://blog.csdn.net/weixin_42321963/article/details/82490804

第一步:修改工具的编码方式:

IDEA快捷键:ctrl+alt+A

搜索:file encodings

接下来src文件:

在上图位置建立三个文件

文件内容如下:

res_en_US.properties

title=Member Register System
uname=Username


res_zh_CN.properties

title=会员注册系统
uname=用户名


res_zh_TW.properties

title=會員註冊系統
uname=用戶名

然后创建jsp文件

<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="" method="post">
    <select name="lang" onchange="document.forms[0].submit()">
        <option value="">请选择语言</option>
        <option value="zh_CN">汉语</option>
        <option value="en_US">美国英语</option>
        <option value="zh_TW">台湾</option>
    </select>
</form>
<fmt:setLocale value="${param.lang}"/>
<fmt:bundle basename="res">
    <h3><fmt:message key="title"/></h3>
    <fmt:message key="uname"/>:<<input type="text" name="uname"/>
</fmt:bundle>
</body>
</html>

然后打开网页测试:

成功 SUCCESS HAHA

猜你喜欢

转载自blog.csdn.net/weixin_42321963/article/details/82490804