码迷,mamicode.com
首页 > Web开发 > 详细

jsp页面的国际化

时间:2018-02-10 15:50:32      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:server   doc   文件   undle   inf   import   技术分享   context   运行   

三个配置文件:

技术分享图片

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页面的国际化

标签:server   doc   文件   undle   inf   import   技术分享   context   运行   

原文地址:https://www.cnblogs.com/leixia/p/8438730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!