close
一、首先建立一个login.jsp文件
 
<%@ page lang ge="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = reqst.getContextPath();
String basePath = reqst.getScheme()+"://"+reqst.getServerName()+":"+reqst.getServerPort()+path+"/";
%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<!DOCTYPE HTML P LIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="http://blog.163.com/ff/blog/<%=basePath%>">
 
<link rel="stylesheet" href="http://blog.163.com/ff/blog/css/common.css" type="text/css" />
<title>错误页面</title>
</head>
 
<body>
<center>
<!-- login.merchant 指的商户登录帐号-->
<bean:message key="login.merchant"></bean:message>
<input type="text" name="merchantaccount"><br>
<!-- login.username 指的用户登录帐号-->
<bean:message key="login.username"></bean:message>
<input type="text" name="useraccount"><br>
 
<!-- login.password 指的登录密码-->
<bean:message key="login.password"></bean:message>
<input type="text" name="userpassword"><br>
 
<a href="http://blog.163.com/jianglei_jlpps/blog/changeLan.do?lan=zh&country=CN">中文简体</a><br>
<a href="HTTP://blog.163.com/jianglei_jlpps/blog/changeLan.do?lan=en&country=US">Engish</a><br>
<a href="HTTP://blog.163.com/jianglei_jlpps/blog/changeLan.do?lan=zh&country=HK">中文繁體</a><br>
</center>
</body>
</html>
 
二、建立相應的三個資源檔
在com.benks.paypay.Resources資料夾下建立
 
1.ApplicationResources_en_US.properties
 
login.password = password
login.merchant = Merchant ID
login.username = UserName
 
2.ApplicationResources_zh_CN.properties
 
login.password=\密\碼
login.merchant=\商\戶\號
login.username=\用\戶\名
 
3.ApplicationResources_zh_HK.properties
 
login.password=\密\碼
login.merchant=\商\戶\號
login.username=\用\戶\名
 
三.建立一個處理語言改變的Action
 
package com.benks.paypay.action;
 
import java.util.Locale;
 
import javax.servlet.HTTP.HttpServletReqst;
import javax.servlet.HTTP.HttpServletResponse;
 
import org.apache.struts.Globals;
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.actions.DispatchAction;
 
p lic class ChangeLang geAction extends Action{
p lic ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletReqst reqst, HttpServletResponse response)
throws Exception {
String lan = reqst.getParameter("lan");
String country=reqst.getParameter("country");
Locale currentLocale = null;
if ("en".eq ls(lan)&&"US".eq ls(country)) {
currentLocale = new Locale("en", "US");
reqst.getSession().setAttribute("country", "us");
 
//System.out.println("sdfsdfsadfds"+currentLocale.getCountry());
// System.out.println(Globals.LOCALE_KEY);
} else if ("zh".eq ls(lan)&&"CN".eq ls(country)) {
currentLocale = new Locale("zh", "CN");
reqst.getSession().setAttribute("country", "cn");
// System.out.println("sdfsdfsadfds"+currentLocale.getCountry());
//System.out.println("dsfsfsfsdfsdf"+Globals.LOCALE_KEY);
}else if("zh".eq ls(lan)&&"HK".eq ls(country)){
 
currentLocale=new Locale("zh","HK");
reqst.getSession().setAttribute("country", "hk");
}


 
reqst.getSession().setAttribute(Globals.LOCALE_KEY, currentLocale);
return mapping.findForward("loginPage");
 
}
}
 
四、配置strust-config.xml
 
<?xml version="1.0" encoding="ISO-8859-1" ?>
 
<!DOCTYPE struts-config P LIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"HTTP://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
 
</form-beans>
<global-exceptions>
 
</global-exceptions>
<global-forwards>
 
</global-forwards>
<action-mappings>



 
<action path="/changeLan"
type="org.springframework.web.struts.DelegatingActionProxy"
scope="reqst"
>
<forward name="loginPage" path="/login.jsp"></forward>
 
</action>
 
</action-mappings>
<message-resources parameter="com/benks/paypay/Resources/ApplicationResources" />
</struts-config>
 
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()