jsp页面的国际化

三个配置文件:

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>

运行结果:

 

转载于:https://www.cnblogs.com/leixia/p/8438730.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值