posts - 68, comments - 19, trackbacks - 0, articles - 1
          1.搭建環境
          將項目引入相關jar包:struts1.2 ;jstl,配置struts-config.xml文件
          2.根據struts-config.xml中資源文件配置標簽的basename,配置中文、英文(如果你會火星文也可以)的資源文件。總的說來,國際化工作是量大難點少。
          3.寫好相關action和jsp文件。

          下面是相關配置文件:
          struts-config.xml:

          <?xml version="1.0" encoding="iso-8859-1"?>
          <!DOCTYPE struts-config PUBLIC
                    "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
                    "http://struts.apache.org/dtds/struts-config_1_2.dtd">

          <struts-config>

           <form-beans>
            <form-bean name="stepform" type="org.vle.order.StepActionForm"></form-bean>
           </form-beans>

           <action-mappings>
            <action path="/step"
              type="org.vle.order.StepAction"
              name="stepform"
              parameter="stuts"
              scope="session"
            >
             <forward name="gos1" path="/step1.jsp"/>
             <forward name="gos2" path="/step2.jsp"/>
             <forward name="gos3" path="/step3.jsp"/>
             <forward name="show" path="/show.jsp"/>
             <forward name="ok" path="/suc.jsp"/>
            </action>
           </action-mappings>
           <message-resources parameter="MessageBundle" />

          </struts-config>



          web.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <web-app version="2.4"
           xmlns="http://java.sun.com/xml/ns/j2ee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
           http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
            <welcome-file-list>
              <welcome-file>index.jsp</welcome-file>
            </welcome-file-list>
           
            <servlet>
              <servlet-name>action</servlet-name>
              <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
              <init-param>
                <param-name>config</param-name>
                <param-value>/WEB-INF/struts-config.xml</param-value>
              </init-param>
              <init-param>
                <param-name>debug</param-name>
                <param-value>2</param-value>
              </init-param>
              <init-param>
                <param-name>detail</param-name>
                <param-value>2</param-value>
              </init-param>
              <load-on-startup>2</load-on-startup>
            </servlet>

            <servlet-mapping>
              <servlet-name>action</servlet-name>
              <url-pattern>*.do</url-pattern>
            </servlet-mapping>
          </web-app>

          再寫中文資源文件的時候,雖然myeclipse有的版本也許集成了轉unicode功能,但是最好通過命令行將資源文件編譯成unicode,以免出現亂碼。
          index.begin=\u5f00\u59cb  \u4e3a\u4e2d\u56fd\u7684\u7528\u6237
          step.user=\u7528\u6237
          step.next=\u4e0b\u4e00\u6b65
          step.prod=\u4ea7\u54c1
          step.add=\u5730\u5740
          step.submit=\u63d0\u4ea4
          step.suc=\u6210\u529f

          en:
          index.begin=begin for USA
          step.user=user
          step.next=next
          step.prod=productor
          step.add=address
          step.submit=submit
          step.suc=sucessful book

          Feedback

          # re: 簡單經典的實例--struts1.2框架實現web應用程序的國際化  回復  更多評論   

          2010-12-15 12:40 by 水星家紡
          還不錯
          主站蜘蛛池模板: 汝阳县| 西安市| 大理市| 正宁县| 武威市| 新余市| 武宣县| 宿州市| 通河县| 横峰县| 福安市| 南雄市| 恩平市| 海南省| 滨州市| 舟山市| 满城县| 乐亭县| 册亨县| 平原县| 读书| 萨迦县| 建始县| 阿拉善右旗| 乐昌市| 夏津县| 井陉县| 丹棱县| 依兰县| 云浮市| 沧州市| 莱西市| 日喀则市| 五大连池市| 鄯善县| 东至县| 平果县| 陇南市| 大关县| 哈巴河县| 潞城市|