zoukankan      html  css  js  c++  java
  • struts2学习(10)struts2国际化

    一、国际化简介:

    二、struts2国际化设置:

    struts.xml:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
    
    <struts>
        
        <constant name="struts.custom.i18n.resources" value="i18n"></constant>
        
    </struts>

    上面取的value为‘i18n’,默认加载的资源文件名字为i18n.properties;  默认语言采用中文;

    中文加载的资源文件为:i18n_zh_CN.properties;

    英文加载的资源文件为:i18n_en_US.properties;

    i18n.properties:

    因为中文放在properties中使用unicode编码,userName对应的是'用户名'.......

    {0}指的是第0个位置,参数的占位符。

    userName=u7528u6237u540d
    password=u5bc6u7801
    login=u767bu5f55
    welcomeInfo=u6b22u8fce{0}

    i18n_zh_CN.properties:

    userName=u7528u6237u540d
    password=u5bc6u7801
    login=u767bu5f55
    welcomeInfo=u6b22u8fce{0}

    i18n_en_US.properties:

    userName=userName
    password=password
    login=login
    welcomeInfo=welcome{0}

    login.jsp:

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <%@taglib prefix="s" uri="/struts-tags" %>
    <!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>Insert title here</title>
    </head>
    <body>
    <table>
        <tr>
            <td><s:text name="userName"></s:text></td>
            <td>
                <input type="text"/>
            </td>
        </tr>
        <tr>
            <td><s:text name="password"></s:text></td>
            <td>
                <input type="text"/>
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="<s:text name='login'></s:text>"/>
            </td>
        </tr>
    </table>
    </body>
    </html>

    welcome.jsp:

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <%@taglib prefix="s" uri="/struts-tags" %>
    <!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>Insert title here</title>
    </head>
    <body>
    <s:text name="welcomeInfo">
        <s:param>Jack</s:param>
    </s:text>
    </body>
    </html>

    中文测试:

    英文测试:

  • 相关阅读:
    core.net 创建coreclass 项目出现一些问题
    【BZOJ4144】[AMPPZ2014]Petrol 最短路+离线+最小生成树
    【BZOJ4774/4006】修路/[JLOI2015]管道连接 斯坦纳树
    【BZOJ2595】[Wc2008]游览计划 斯坦纳树
    【BZOJ4149】[AMPPZ2014]Global Warming 单调栈+RMQ+二分
    【BZOJ4764】弹飞大爷 LCT
    【BZOJ3529】[Sdoi2014]数表 莫比乌斯反演+树状数组
    【BZOJ5008】方师傅的房子 三角剖分
    【BZOJ4282】慎二的随机数列 乱搞
    【BZOJ1568】[JSOI2008]Blue Mary开公司 线段树
  • 原文地址:https://www.cnblogs.com/tenWood/p/7103728.html
Copyright © 2011-2022 走看看