<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 32,  comments - 149,  trackbacks - 0

    1.引言
    ? 因?yàn)樽罱袀€(gè)英國(guó)的項(xiàng)目要求中英文切換,又由于我們開(kāi)發(fā)是用struts+hibernate的,所以我們就把原先做兩個(gè)版本的構(gòu)思拋掉,就用struts的國(guó)際化處理方案。
    2.資料
    ? 首先,我們要準(zhǔn)備兩份配置文件中文和英文的
    ? 中文:ApplicationResources_zh_CN.properties
    ? 英文:ApplicationResources_en.properties? (千萬(wàn)不要用默認(rèn)的ApplicationResources.properties myeclipse自動(dòng)生成,可能會(huì)不成功,我起先就是因?yàn)檫@個(gè)怎么都不行的,呵呵!)
    3.準(zhǔn)備開(kāi)始
    1)?ApplicationResources_zh_CN.properties的內(nèi)容
    #zh_CN
    username=純冰
    2)ApplicationResources_en.properties的內(nèi)容
    #en
    username=chunkyo
    3)一個(gè)action
    /*
    ?* Generated by MyEclipse Struts
    ?* Template path: templates/java/JavaClass.vtl
    ?*/
    package com.lan.struts.action;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;

    import org.apache.struts.Globals;
    import java.util.Locale;

    /**
    ?* MyEclipse Struts
    ?* Creation date: 02-07-2007
    ?*
    ?* XDoclet definition:
    ?* @struts.action validate="true"
    ?*/
    public class ChangeLanguageAction extends Action {
    ?/*
    ? * Generated Methods
    ? */

    ?/**
    ? * Method execute
    ? * @param mapping
    ? * @param form
    ? * @param request
    ? * @param response
    ? * @return ActionForward
    ? */
    ?public ActionForward execute(ActionMapping mapping, ActionForm form,
    ???HttpServletRequest request, HttpServletResponse response) {
    ??// TODO Auto-generated method stub
    ??String lan=request.getParameter("lan");
    ??if(lan.equals("1"))
    ??{
    ???request.getSession().setAttribute(Globals.LOCALE_KEY,Locale.CHINA);
    ??}
    ??else if(lan.equals("0"))
    ??{
    ???request.getSession().setAttribute(Globals.LOCALE_KEY,Locale.ENGLISH);
    ??}
    ??else
    ??{
    ???request.getSession().setAttribute(Globals.LOCALE_KEY,Locale.CHINA);
    ??}
    ??return mapping.findForward("index");
    ?}
    }

    4)一個(gè)頁(yè)面
    <%@ page language="java" pageEncoding="utf-8"%>
    <%@ taglib uri="<%@ taglib uri="<%@ taglib uri="

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html locale="true">
    ? <head>
    ??? <html:base />
    ???
    ??? <title><bean:message key="username"/></title>

    ?<meta http-equiv="pragma" content="no-cache">
    ?<meta http-equiv="cache-control" content="no-cache">
    ?<meta http-equiv="expires" content="0">???
    ?<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    ?<meta http-equiv="description" content="This is my page">
    ?<!--
    ?<link rel="stylesheet" type="text/css" href="styles.css">
    ?-->

    ? </head>
    ?
    ? <body>
    ??? <html:link page="/changeLanguage.do?lan=0">English</html:link>
    ??? <html:link page="/changeLanguage.do?lan=1">Chinese</html:link>
    ??? <bean:message key="username"/>
    ? </body>
    </html:html>
    4)配置文件(struts-config.xml)
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "

    <struts-config>
    ? <data-sources />
    ? <form-beans />
    ? <global-exceptions />
    ? <global-forwards >
    ??? <forward name="index" path="/index.jsp" />

    ? </global-forwards>

    ? <action-mappings >
    ??? <action path="/changeLanguage" type="com.lan.struts.action.ChangeLanguageAction" />

    ? </action-mappings><message-resources parameter="com.lan.struts.ApplicationResources" />
    </struts-config>

    5)結(jié)果
    ?1。默認(rèn)
    http://localhost:8080/lan/
    EnglishChinese 純冰
    2。英文
    http://localhost:8080/lan/changeLanguage.do?lan=0
    EnglishChinese chunkyo
    3。中文
    http://localhost:8080/lan/changeLanguage.do?lan=1
    EnglishChinese 純冰
    6)結(jié)論
    用struts做國(guó)際化處理 多國(guó)語(yǔ)言處理很方便 呵呵!

    posted on 2007-02-07 13:08 chunkyo 閱讀(3552) 評(píng)論(3)  編輯  收藏 所屬分類: openSource(struts&hibernate&spring等等)

    FeedBack:
    # re: struts多國(guó)語(yǔ)言國(guó)際化處理(現(xiàn)以中文英文切換為例)
    2007-02-08 18:57 | keith
    當(dāng)你使用tiles來(lái)組裝不同JSP頁(yè)面時(shí),你就發(fā)現(xiàn)不那么好用了。有時(shí)候只有部分頁(yè)面切換了,運(yùn)行不穩(wěn)定。  回復(fù)  更多評(píng)論
      
    # re: struts多國(guó)語(yǔ)言國(guó)際化處理(現(xiàn)以中文英文切換為例)[未登錄](méi)
    2007-02-12 01:57 | chunkyo
    沒(méi)有啊,我現(xiàn)在就一直再用的 沒(méi)感覺(jué)不好用的,最近在做一個(gè)交友網(wǎng)站的,
    英國(guó)方面要的,所以得有中英文切換,現(xiàn)在運(yùn)行還行 沒(méi)出現(xiàn)你說(shuō)的!  回復(fù)  更多評(píng)論
      
    # re: struts多國(guó)語(yǔ)言國(guó)際化處理(現(xiàn)以中文英文切換為例)[未登錄](méi)
    2007-11-29 16:27 | jeff
    請(qǐng)問(wèn)一下,你在新建ApplicationResources_zh_CN.properties文件的時(shí)候,文件編碼改為了什么。是UTF-8嗎  回復(fù)  更多評(píng)論
      
    <2007年2月>
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728123
    45678910

    這個(gè)博客主要是關(guān)于java技術(shù)和開(kāi)源技術(shù),大家一起來(lái)進(jìn)步了!

    常用鏈接

    留言簿(12)

    隨筆分類

    隨筆檔案

    文章分類

    收藏夾

    DotNet

    Java技術(shù)網(wǎng)站

    Linux VS Unix

    其他常去網(wǎng)站

    常光顧的BLOG

    文學(xué)類網(wǎng)站

    游戲類網(wǎng)站

    最新隨筆

    搜索

    •  

    積分與排名

    • 積分 - 196777
    • 排名 - 293

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 国产午夜亚洲精品理论片不卡 | 亚洲av无码一区二区三区观看| 国产精品嫩草影院免费| 精品久久8x国产免费观看| 中文字幕av无码不卡免费| 色婷婷亚洲一区二区三区| 亚洲欧洲日韩极速播放| 亚洲伊人精品综合在合线| 亚洲电影国产一区| 亚洲国产无套无码av电影| 日批日出水久久亚洲精品tv| 午夜毛片不卡免费观看视频| 国产精品色拉拉免费看| 99re在线精品视频免费| 182tv免费视频在线观看| 国产乱子伦精品免费视频| 美女尿口扒开图片免费| 欧美日韩亚洲精品| 亚洲日韩亚洲另类激情文学| 亚洲av一本岛在线播放| 久久久久精品国产亚洲AV无码| 亚洲第一页中文字幕| 亚洲精品在线播放视频| 亚洲情a成黄在线观看动漫尤物| 亚洲精品~无码抽插| 亚洲熟妇无码另类久久久| 国产亚洲美女精品久久久2020| MM131亚洲国产美女久久| 亚洲精品无码久久久| 在线精品亚洲一区二区小说 | 特a级免费高清黄色片| 美女视频黄.免费网址 | 亚洲精品国产V片在线观看| 在线a亚洲v天堂网2018| 亚洲人成无码网站久久99热国产| 亚洲第一区精品观看| 国产精品亚洲αv天堂无码| 中文亚洲AV片在线观看不卡| 亚洲色大成网站www永久一区| 亚洲男同帅GAY片在线观看| 久久精品国产亚洲夜色AV网站|