1 准备资源文件。
资源文件命名格式:filename_language_country.properties.
中文文件名为index_zh_cn.properties。
日文文件名为 index_ja_jp.properties。
英文文件名为 index_en.properties。
英文文件内容:
index.jsp.welcome=colimas library management system
index.jsp.name=name
index.jsp.userid=user id
index.jsp.pass=password
index.jsp.welcome=\u4f60\u597d
index.jsp.name=\u59d3\u540d
index.jsp.userid=\u7528\u6237\u540d
index.jsp.pass=\u5bc6\u7801
index.jsp.welcome=\u3044\u3089\u3063\u3057\u3083\u3044\u307e\u305b
index.jsp.name=\u59d3\u540d
index.jsp.userid=\u30e6\u30fc\u30b6\u30fcid
index.jsp.pass=\u30d1\u30b9\u30ef\u30fc\u30c9
<message-resources parameter="resources.config.index" />
<form-beans>
<!--1 multi-lanuage support formbean-->
<form-bean
name="selectlanguageform"
type="com.nova.colimas.web.form.selectlanguageform"/>
</form-beans>
<!-- =========================================== global forward definitions -->
<global-forwards>
<!-- default forward to "welcome" action -->
<!-- demonstrates using index.jsp to forward -->
<forward
name="index"
path="/pages/index.jsp"/>
</global-forwards>
<!-- =========================================== action mapping definitions -->
<action-mappings>
<!-- 1 select language action -->
<action path="/selectlanguageaction"
type="com.nova.colimas.web.action.selectlanguageaction"
name="selectlanguageform"
scope="request">
</action>
…
</action-mappings>
<%@ page contenttype="text/html; charset=utf-8"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<html:html>
<title><bean:message key="index.jsp.welcome"/></title>
<body>
<logic:present name="user">
<h3>welcome <bean:write name="loginform" property="userid" />!</h3>
</logic:present>
<logic:notpresent scope="session" name="user">
<h3>welcome colimas!</h3>
</logic:notpresent>
<html:errors />
<html:form action="/selectlanguageaction.do">
<html:select property="language">
<html:option value="0">中文</html:option>
<html:option value="1">日本語</html:option>
<html:option value="2">english</html:option>
</html:select>
<html:submit>select</html:submit>
</html:form>
<html:form action="/loginaction.do">
<p><bean:message key="index.jsp.userid"/><input type="text" name="userid" value="tyrone1979" /><br>
<bean:message key="index.jsp.pass"/><input type="password" name="password" value="197913"/><br>
<html:submit><bean:message key="index.jsp.login"/></html:submit>
</p>
</html:form>
</body>
</html:html>
package com.nova.colimas.web.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.action.actionmessages;
//import org.apache.struts.upload.formfile;
import com.nova.colimas.web.form.selectlanguageform;
import org.apache.struts.globals;
import java.util.locale;
public class selectlanguageaction extends action {
public actionforward execute(actionmapping mapping,
actionform form,
httpservletrequest request,
httpservletresponse response)
throws exception{
selectlanguageform myform=(selectlanguageform)form;
string lan=myform.getlanguage();
switch((new integer(lan)).intvalue()){
case 0 :
request.getsession().setattribute(globals.locale_key,locale.china);
break;
case 1:
request.getsession().setattribute(globals.locale_key, locale.japan);
break;
case 2:
request.getsession().setattribute(globals.locale_key, locale.english);
break;
default:
request.getsession().setattribute(globals.locale_key, locale.english);
break;
}
return mapping.findforward("index");
}
}
form
/*
* created on 2005/06/18
*
* todo to change the template for this generated file go to
* window - preferences - java - code style - code templates
*/
package com.nova.colimas.web.form;
import org.apache.struts.action.actionform;
/**
* @author tyrone
**/
public class selectlanguageform extends actionform {
private string language;
public void reset() {
this.language="";
return;
}
/**
* @return returns the language.
*/
public string getlanguage() {
return language;
}
/**
* @param language the language to set.
*/
public void setlanguage(string property1) {
this.language = property1;
}
}
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器