三个配置文件:
myproperties_en.properties是英文的:
myproperties_zh.properties是中文的:
jsp页面的代码:
<%@ page language="java" import="java.util.*" pageEncoding="uTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
?<head>
???<base href="<%=basePath%>"> ???
???<title>国际化(i18n)测试</title>
?</head>
?
?<body>
?<!-- 第一种方式 -->
??<fmt:setBundle basename="property.myproperties" scope="page" ?var="bundle"/>
???<form action="">
????<fmt:message key="username" bundle="${bundle}"/><input type="text" name="username"><br/>
???????<fmt:message key="password" bundle="${bundle}"/><input type="password" name="password"><br/>
???????<input type="submit" value="<fmt:message key="submit" bundle="${bundle}"/>">
???</form>
??<!-- 第二种方式 -->
???<fmt:bundle basename="property.myproperties" >
???<form action="">
???<fmt:message key="username" /><input type="text" name="username"><br/>
???<fmt:message key="password" /><input type="password" name="password"><br/>
???<input type="submit" value="<fmt:message key="submit"/>">
???</form>
???
???</fmt:bundle>
?</body>
</html>
运行结果:
jsp页面的国际化
原文地址:https://www.cnblogs.com/leixia/p/8438730.html