环境:引入库jstl,含jstl.jar和stardard.jar两个包
编写两个属性文件:MyMutiLanguage_en_US.properties和MyMutiLanguage_zh_CN.properties
内容分别为:testkey=it_is_test和testkey=测试
页面Muti_LanguageTest代码如下:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Muti-Language Test</title>
</head>
<body>
<fmt:bundle basename="MyMutiLanguage_en_US" prefix="test">
<fmt:message key="key"></fmt:message>
</fmt:bundle>
<fmt:bundle basename="MyMutiLanguage_zh_CN">
<fmt:message key="testkey"></fmt:message>
</fmt:bundle>
<fmt:setLocale value="zh_CN"></fmt:setLocale>
<fmt:bundle basename="MyMutiLanguage">
<fmt:message key="testkey"></fmt:message>
</fmt:bundle>
</body>
</html>
运行后,页面显示结果如下:
it_is_test 测试 测试