spring i18n, struts i18n

一、spring

1.spring bean设定:

View Code
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>i18n.labels</value>
                <value>i18n.messages</value>
                <value>i18n.errors</value>
                <value>i18n.db.labels</value>
                <value>i18n.db.messages</value>
                <value>i18n.db.errors</value>
            </list>
        </property>
    </bean>

2. 页面上使用

  (1)直接bundle

<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
    <fmt:bundle basename="i18n.labels">
    <body>
            <fmt:message key="com.lab.seq"/>
    </body>
    </fmt:bundle>
</html>

 

  (2)通过别名bundle

<!-- basename 就是配置文件中的value, var是别名-->
  <fmt:setBundle basename="i18n.messages" var="msg"/>
  <!-- key i18n文件中的key,bundle 就是刚才定义的别名-->
  <fmt:message key="com.lab.seq" bundle="${msg }"/>
<!-- taglib 不可以嵌套, 如果遇到嵌套可以使用以下方式 -->
  <!-- 1. 定义 文字,比刚才多一个var别名:有了别名这一行就不会显示了 -->
  <fmt:message key="com.lab.seq" bundle="${msg }" var="labSeq"/>
  <!-- 2. 直接使用, 可以在任意位置使用了 -->
  ${labSeq}

 

二、struts

1. 配置文件

    <constant name="struts.custom.i18n.resources"
        value="i18n/messages,i18n/labels,i18n/errors,i18n/db/messages,i18n/db/labels,i18n/db/errors" />

2. 页面上使用

<!--直接使用struts标签-->
     <s:property value="%{getText('com.lab.seq')}"/>
     <s:text name="com.lab.seq"/>
     <s:submit value="%{getText('com.btn.qry')}"/>
<!-- 在struts标签以外使用-->
    <!-- 1. 定义变量, 定义变量后此行不显示-->
    <s:text name="com.lab.seq" var="labSeq"/>
    <!-- 2. 在非struts标签中使用 -->
    <input type="submit" value="${labSeq}">

 

 



posted @ 2013-03-05 15:24  秋日私语的博客  阅读(1325)  评论(0编辑  收藏  举报