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

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

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

    love fish大鵬一曰同風起,扶搖直上九萬里

    常用鏈接

    統計

    積分與排名

    friends

    link

    最新評論

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

    1.引言
    ? 因為最近有個英國的項目要求中英文切換,又由于我們開發是用struts+hibernate的,所以我們就把原先做兩個版本的構思拋掉,就用struts的國際化處理方案。
    2.資料
    ? 首先,我們要準備兩份配置文件中文和英文的
    ? 中文:ApplicationResources_zh_CN.properties
    ? 英文:ApplicationResources_en.properties? (千萬不要用默認的ApplicationResources.properties myeclipse自動生成,可能會不成功,我起先就是因為這個怎么都不行的,呵呵!)
    3.準備開始
    1)?ApplicationResources_zh_CN.properties的內容
    #zh_CN
    username=純冰
    2)ApplicationResources_en.properties的內容
    #en
    username=chunkyo
    3)一個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)一個頁面
    <%@ 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)結果
    ?1。默認
    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)結論
    用struts做國際化處理 多國語言處理很方便 呵呵!

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

    評論

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

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

    # re: struts多國語言國際化處理(現以中文英文切換為例) (轉) 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.)
      回復  更多評論   

    主站蜘蛛池模板: 最新国产精品亚洲| 成年人网站免费视频| 四虎国产精品免费永久在线| 美国免费高清一级毛片| 在线亚洲v日韩v| 一级成人a做片免费| 国产免费高清69式视频在线观看| 人妻仑乱A级毛片免费看| 一个人看的www免费高清 | 亚洲人成77777在线播放网站不卡| 亚洲综合一区二区精品导航| 久久综合亚洲鲁鲁五月天| 337p日本欧洲亚洲大胆色噜噜| 亚洲高清在线mv| 亚洲www在线观看| 日本一区二区在线免费观看| 久久久精品免费国产四虎| 18禁网站免费无遮挡无码中文| 热99re久久免费视精品频软件| 国产三级电影免费观看| 亚洲黑人嫩小videos| 美女视频免费看一区二区| 亚洲日本在线免费观看| ZZIJZZIJ亚洲日本少妇JIZJIZ| 亚洲伊人久久大香线蕉| 中文字幕免费在线观看动作大片| 可以免费看黄视频的网站| 亚洲日本乱码在线观看| 亚洲国产成人久久精品大牛影视 | 自拍偷区亚洲国内自拍| 免费看搞黄视频网站| 亚洲国产日韩在线观频| 亚洲精品无码一区二区 | 香港a毛片免费观看 | 精品无码无人网站免费视频| 日韩精品视频免费观看| 亚洲午夜精品在线| 67194成手机免费观看| 亚洲黄色高清视频| 成人免费区一区二区三区 | 亚洲AV无码成人网站在线观看|