struts2 国际化

  1. struts.xml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?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="bundles.resourcebundle"/>
    <constant name="struts.i18n.encoding" value="UTF-8"/>
    <constant name="struts.ui.theme" value="simple" />
    <include file="struts-mesLineStatusMonitor.xml"/>
    </struts>

2.和struts.xml同级新建bundles文件夹,并建resourcebundle.properties,resourcebundle_en_US.properties,resourcebundle_zh_CN.properties

resourcebundle_en_US.properties

1
row2.uph = UPH

resourcebundle_zh_CN.properties

1
row2.uph = 每小时产量

如果从上面两个文件找不到,会默认加载resourcebundle.properties里面的内容

  1. struts-mesLineStatusMonitor.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    <?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>
    <package name="epanelView" extends="struts-portlet-default" namespace="/view">
    <action name="lineStatusMonitorIndex" class="lineStatusAction" method="index">
    <result name="success">/view/lineStatusMonitor.jsp</result>
    </action>
    </package>
    <package name="Struts2_AJAX_JASON" extends="json-default">
    <interceptors>
    <interceptor-stack name="myDefaultStack">
    <interceptor-ref name="json" />
    <interceptor-ref name="defaultStack" />
    </interceptor-stack>
    </interceptors>
    <default-interceptor-ref name="myDefaultStack" />
    <action name="addLineStautsMonitorConfigs" class="lineStatusAction" method="addLineStautsMonitorConfigs">
    <result type="json"></result>
    </action>
    <action name="loadLineStautsMonitorConfigs" class="lineStatusAction" method="loadLineStautsMonitorConfigs">
    <result type="json">
    <param name="root">lineStatusMonitorConfigs</param>
    </result>
    </action>
    <action name="loadMfgLines" class="lineStatusAction" method="loadMfgLines">
    <result type="json">
    <param name="root">mfgLines</param>
    </result>
    </action>
    <action name="loadProcesses" class="lineStatusAction" method="loadProcesses">
    <result type="json">
    <param name="root">processes</param> <!--process-->
    </result>
    </action>
    <action name="loadPartNumbers" class="lineStatusAction" method="loadPartNumbers">
    <result type="json">
    <param name="root">partNumbers</param>
    </result>
    </action>
    <action name="loadWorkOrders" class="lineStatusAction" method="loadWorkOrders">
    <result type="json">
    <param name="root">workOrders</param>
    </result>
    </action>
    <action name="loadWorkstations" class="lineStatusAction" method="loadWorkstations">
    <result type="json">
    <param name="root">workstations</param> <!--workstions-->
    </result>
    </action>
    <action name="loadLineStatusMonitorAreas" class="lineStatusAction" method="loadLineStatusMonitorAreas">
    <result type="json">
    <param name = "root">lineStatusMonitorAreas</param>
    </result>
    </action>
    </package>
    </struts>
  2. lineStatusMonitor.jsp

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <%@ page import="java.util.ResourceBundle"%>
    <%@ page import="java.util.Locale"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <%
    ResourceBundle bundle = portletConfig.getResourceBundle(locale);
    %>
    <script>
    uphLabel = "<div{display:inline;} class=\"label\">"+ "<%=bundle.getString("row2.uph")%>" +"</div>";
    </script>