虚位以待(AD)
虚位以待(AD)
首页 > 网络编程 > JSP编程 > ResourceBundle类在jsp中的国际化实现方法

ResourceBundle类在jsp中的国际化实现方法
类别:JSP编程   作者:码皇   来源:互联网   点击:

下面小编就为大家带来一篇ResourceBundle类在jsp中的国际化实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

今天第一次听说页面国际化这个词,所以查资料,顺便做了一个小页面,做做记录。

首先是两个资源文件,分别为msg_en_US.properties和msg_zh_CN.properties

 

显然中文字符是需要转换过来的。

这是jsp页面的代码

    <%@ page language="java" contentType="text/html;
    charset=UTF-8" pageEncoding="UTF-8"%><%@page import="java.util.*"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="Content-Type" content="text/html;
    charset=UTF-8"> <title>国际化</title> <style type="text/css"> div{
    width: 300px;
    text-align: center;
    margin: 0 auto;
    }
    </style> </head> <body> <a href="/International/test.jsp?language=zh" rel="external nofollow" >简体中文</a>|<a href="/International/test.jsp?language=en" rel="external nofollow" >English</a> <% ResourceBundle bund=ResourceBundle.getBundle("msg",request.getLocale());
    String str=request.getParameter("language");
    if(str!=null){
    if("zh".equals(str)){
    bund=ResourceBundle.getBundle("msg",Locale.CHINA);
    }
    else if("en".equals(str)){
    bund=ResourceBundle.getBundle("msg",Locale.US);
    }
    }
    %> <div> <h1><%=bund.getString("inf") %></h1> <table> <tr> <td><%=bund.getString("name") %>:</td> <td><input type="text" name="name"/></td> </tr> <tr> <td><%=bund.getString("sex") %>:</td> <td><input type="text" name="sex"/></td> </tr> <tr> <td><%=bund.getString("age") %>:</td> <td><input type="text" name="age"/></td> </tr> <tr> <td><%=bund.getString("tel") %>:</td> <td><input type="text" name="tel"/></td> </tr> </table><br/> <input type="submit" value="<%=bund.getString("submit")%>" name="submit"/> </div> </body></html>

结果图

 

以上这篇ResourceBundle类在jsp中的国际化实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关热词搜索: jsp 国际化