资源国际化-Struts2

    xiaoxiao2021-09-17  84

    【1】

    Struts2 里面使用了一系列的拦截器,封装了一系列方法,可以很方便进行资源国际化。

    【2】

    Struts2 国际化是建立在 Java 国际化基础上的: 为不同国家/语言提供对应的消息资源文件 Struts2 框架会根据请求中包含的 Locale 加载对应的资源文件 通过程序代码取得该资源文件中 指定 key 对应的消息

    【3】

    配置国际化资源文件几点事宜:

    【4】

    配置实例:

    【5】

    加载国际化资源文件顺序

    【6】

    JSP页面访问国际化资源文件的方式:

    【7】

    通过超链接动态加载国际化资源文件流程分析

    【8】

    运行流程图

    【9】

    实例代码:

    通过index.jsp <a href="testi18n.action"></a>,默认执行Action的execute方法,跳转到下面JSP页面

    JSP页面代码: <body> <!-- 页面上可以直接使用 s:text标签来访问国际化资源文件中的属性值 --> <s:debug></s:debug> <a href="testI18n.action?request_locale=en_US">English</a> <a href="testI18n.action?request_locale=zh_CN">中文</a> <br><br> <a href="index.jsp">index JSP</a> <hr> <%-- 这个注释符号很好用!!!!,客户端隐藏注释--%> <s:text name="time"> <!-- get the value in ObjectStack --> <s:param value="date"></s:param> </s:text> <br><br> <s:text name="time2"> </s:text> <s:form action="" theme="simple"> <s:text name="username"/>:<s:textfield name="username" label="%{getText('username')}"></s:textfield> <br/><br/> <!-- key is direct to resource properties get its value --> <s:text name="username"/>:<s:textfield name="username" key="username"></s:textfield> <br/><br/> <s:text name="password"/>:<s:textfield name="password" key="password"></s:textfield> <br/><br/> <s:submit key="submit" value="%{getText('submit')}"></s:submit> </s:form> </body>
    转载请注明原文地址: https://ju.6miu.com/read-677677.html

    最新回复(0)