国际化的实现

通过登录页面实现国际化
1.编写properties文件
(1)英文
例如;名字是ApplicationResources_en_US.properties
内容:
[color=blue]title=OA System
userName=username
password=passpwd

submit=submit
reset=reset[/color]
是键值对,通过左侧的键来查询右侧的值
(2)简体中文
例如:ApplicationResources_zh_CN.properties(注意后缀,这与你的浏览器有直接的关系,国际化的实现就是不同地区的浏览器默认的字体不一样的,如果是中国大陆浏览器产送的请求中字体就是zh_CN,就是通过这个后缀来实现国际化,英国默认的语言是(en_GB)通过浏览器打开的就是英国英语)
内容:
[color=blue]title=\u529e\u516c\u81ea\u52a8\u5316\u7cfb\u7edf
userName=\u7528\u6237\u540d
password=\u5bc6\u7801

submit=\u767b\u5f55
reset=\u91cd\u7f6e[/color]
上面的值是中文的ascii码,查询中文的ascii码,有很多工具,这里说一个都有的(只要你安装了JDK)在JDK 的bin目录下,有一个native2ascii.exe的可执行文件点击打开输入你要的汉字,回车就可以了,然后标记一下复制就可以了。
(3)其他语言按照书写格式书写就可以了
不知道了可到IE浏览器上查询各个国家语言的后缀名,右击IE浏览器点击“语言”按钮,
你看到的是当前你的浏览器的语言,点击‘添加’按钮所有的属性都列出来了,
全部中文
中国大陆(zh_CN)中国香港(zh_HK)中国台湾(zh_TW)中国澳门(zh_MO)新加坡(zh_SG)
2.配置web.xml文件
在apache-tomcat-5.5.25\webapps\OA\WEB-INF\web.xml文件中加入
[color=blue]<!-- 国际化标签 -->
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.localizationContext
</param-name>
<param-value>ApplicationResources(这个地方要与上面写的文件名一致)</param-value>
</context-param>[/color]

3.写登录页面的jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
[color=red]<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>[/color]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function checklogin(){

if(document.form1.userName.value==""){
alert("用户名不能位空!");
return ;
}
if(document.form1.password.value==""){
alert("密码不能为空!");
return ;
}
document.form1.submit();
}
</script>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body background="images/index.bmp"> <center>
<c:set var="error" value="${error}"/>
<form method="post" action="login.do" name="form1">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<table width="200" border="1" bordercolor="#4a0115" bordercolorlight="#0099FF" bordercolordark="red" >

<tbody>

<tr>
<td colspan=2>

[color=red]<fmt:message key="title"/></[/color]td>
</tr>
<tr>
<td[color=red]><fmt:message key="userName"/></[/color]td>
<td><input id="userName" type="text" name="userName" value=""></td>
</tr>

<tr>
<td[color=red]><fmt:message key="password"/></[/color]td>
<td><input type="password" name="password" value=""></td></tr>
<tr><td colspan=2><font color="red" >${error}</font>
</td></tr>
<tr>
<td><INPUT name="asubmit" type="button" value[color=red]=<fmt:message key="submit"/>[/color] οnclick="checklogin()"/></td>
<td><input name="areset" type="reset" value[color=red]=<fmt:message key="reset"/>[/color] /></td>

</tr>

</tbody></table>
</form>
</center>
</body>
</html>

声明标签<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

用法:<fmt:message key="title"/>
这样就可一查询properties下的值了key键所对应的值了


ok,国际化实现了!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值