国际化开发二—案例

1.建立3个资源文件(默认,中文,英文) MessageResource.propertiesMessageResource_zh.propertiesMessageResource_en.properties

MessageResource.properties:
username = username
password = password
MessageResource_zh.properties:
username = \u7528\u6237\u540d
password = \u5bc6\u7801
MessageResource_en.properties:
username = username
password = password

2.写登录界面 login.jsp

<%@ page import="java.util.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    国家化的页面


<%
    //bundle根据来访者的国家去选资源文件
    ResourceBundle bundle = ResourceBundle.getBundle("cn.itcast.resource.MessageResource",request.getLocale());
%>

<%=bundle.getString("username")%>:
<%=bundle.getString("password")%>:
">

3.现在我想在登录界面添加两个链接,点中文出现中文页面,点英文出现英文页面:

<%@ page import="java.util.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    国家化的页面


<%
    String language = request.getParameter("language");
    if (language == null || language.equals("")) {
        language = "zh";
    }

    Locale locale = new Locale(language);
    ResourceBundle bundle = ResourceBundle.getBundle("cn.itcast.resource.MessageResource", locale);
    //bundle根据来访者的国家去选资源文件
   // ResourceBundle bundle = ResourceBundle.getBundle("cn.itcast.resource.MessageResource", request.getLocale());
%>

中文(网页)
english(pages)

<%=bundle.getString("username")%>:
<%=bundle.getString("password")%>:
">

你可能感兴趣的:(国际化开发二—案例)