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

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

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

    love fish大鵬一曰同風(fēng)起,扶搖直上九萬里

    常用鏈接

    統(tǒng)計(jì)

    積分與排名

    friends

    link

    最新評(píng)論

    struts多國語言國際化處理(現(xiàn)以中文英文切換為例) (轉(zhuǎn))

    1.引言
    ? 因?yàn)樽罱袀€(gè)英國的項(xiàng)目要求中英文切換,又由于我們開發(fā)是用struts+hibernate的,所以我們就把原先做兩個(gè)版本的構(gòu)思拋掉,就用struts的國際化處理方案。
    2.資料
    ? 首先,我們要準(zhǔn)備兩份配置文件中文和英文的
    ? 中文:ApplicationResources_zh_CN.properties
    ? 英文:ApplicationResources_en.properties? (千萬不要用默認(rèn)的ApplicationResources.properties myeclipse自動(dòng)生成,可能會(huì)不成功,我起先就是因?yàn)檫@個(gè)怎么都不行的,呵呵!)
    3.準(zhǔn)備開始
    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è)頁面
    <%@ page language="java" pageEncoding="utf-8"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>

    <!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" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

    <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做國際化處理 多國語言處理很方便 呵呵!

    posted on 2007-03-23 09:39 liaojiyong 閱讀(2598) 評(píng)論(2)  編輯  收藏 所屬分類: Struts

    評(píng)論

    # re: struts多國語言國際化處理(現(xiàn)以中文英文切換為例) (轉(zhuǎn)) 2007-12-20 14:35 jiangyang_001631@163.com

    請問:如果我想在其它頁面也實(shí)現(xiàn)中英文切換連接,選擇后返回到當(dāng)前請求的頁面,而不是你實(shí)現(xiàn)的固定的“index.jsp”頁面,這樣的效果如何來實(shí)現(xiàn)?   回復(fù)  更多評(píng)論   

    # re: struts多國語言國際化處理(現(xiàn)以中文英文切換為例) (轉(zhuǎn)) 2008-06-11 13:42 na

    Abstract: This paper characterises the dynamics of advertising investment in a spatial monopoly, contrasting the socially optimal behaviour of a benevolent planner against that of a profit-seeking monopolist. In steady state, the monopolist always distorts both output and advertising decisions as compared to the social optimum, except in a situation where, under both monopoly and social planning, the equilibrium entails full market coverage. © 2004 Elsevier B.V. All rights reserved. (27 refs.)
      回復(fù)  更多評(píng)論   

    主站蜘蛛池模板: 亚洲av成人一区二区三区观看在线 | 大学生a级毛片免费观看| 亚洲日韩精品A∨片无码| 亚洲精品视频免费观看| 特级淫片国产免费高清视频| 亚洲免费观看在线视频| 成人片黄网站A毛片免费| 亚洲娇小性色xxxx| 午夜免费福利在线| 日日摸日日碰夜夜爽亚洲| 日韩亚洲精品福利| EEUSS影院WWW在线观看免费| 亚洲码国产精品高潮在线| 久久大香伊焦在人线免费| 亚洲高清中文字幕综合网| 午夜国产精品免费观看| 久久久久久亚洲精品无码| 亚洲av麻豆aⅴ无码电影| 精品乱子伦一区二区三区高清免费播放 | 亚洲国产美女在线观看| 在线看免费观看AV深夜影院| 一本天堂ⅴ无码亚洲道久久| 无码视频免费一区二三区| 麻豆精品国产免费观看| 美女无遮挡免费视频网站| 亚洲熟女一区二区三区| 2019中文字幕在线电影免费 | 亚洲黄色免费网站| 亚洲乱亚洲乱妇24p| 亚洲国产日韩在线观频| 久久青草免费91线频观看站街| 亚洲国产综合专区电影在线 | 亚洲H在线播放在线观看H| 日韩中文字幕在线免费观看| 国产免费久久精品丫丫| 亚洲色图校园春色| 亚洲Av无码国产情品久久| 久久久久久毛片免费播放| 粉色视频成年免费人15次| 亚洲人成电影在线天堂| 国产美女a做受大片免费|