<%--1
使用标签设置
Locale
信息
--%>
<
fmt
:setLocale
value
=""
/>
<%--2
使用标签设置
baseName--%>
<
fmt
:setBundle
basename
=""
/>
<
%--3
输出指定 key 的国际化信息
--%>
<
fmt
:message
key
=""
/>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.ResourceBundle" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%-- <%--%>
<%-- Locale locale =null;--%>
<%-- String country = request.getParameter("country");--%>
<%-- if("china".equals(country)){--%>
<%-- locale=Locale.CHINA;--%>
<%-- }else if("usa".equals(country)){--%>
<%-- locale=Locale.US;--%>
<%-- }else{--%>
<%-- locale=request.getLocale();//从请求头中读取locale语言信息--%>
<%-- }--%>
<%-- //根据basename和locale对象获得resourceBundle类--%>
<%-- ResourceBundle resourceBundle=ResourceBundle.getBundle("i18n"+locale);--%>
<%-- %>--%>
<%-- 使用标签设置locale信息--%>
<fmt:setLocale value="${param.locale}"/>
<%-- 使用标签设置basename--%>
<fmt:setBundle basename="i18n"/>
<%-- <a href="test.jsp?country=china">中文</a>--%>
<%-- <a href="test.jsp?country=usa">English</a>--%>
<a href="test.jsp?locale=zh_CN">中文</a>
<a href="test.jsp?locale=en_US">English</a>
<form>
<table>
<tr>
<%-- <td><%=resourceBundle.getString("username")%></td>--%>
<%-- 输出指定key的国际化信息--%>
<td><fmt:message key="username"/> </td>
<td><input name="username" type="text"/></td>
</tr>
<tr>
<%-- <td><%=resourceBundle.getString("password")%></td>--%>
<td><fmt:message key="password"/> </td>
<td><input name="password" type="password"/></td>
</tr>
<tr>
<%-- <td><%=resourceBundle.getString("reset")%></td>--%>
<td><fmt:message key="reset"/> </td>
<td><input name="reset" type="reset"/></td>
</tr>
<tr>
<%-- <td><%=resourceBundle.getString("submit")%></td>--%>
<td><fmt:message key="submit"/> </td>
<td><input name="submit" type="submit"/> </td>
</tr>
</table>
</form>
</body>
</html>