首页>代码>【猪猪-后端】中英日三版Struts2多语言国际化,一套模版根据语言切换不同CSS,开发必备Demo,部署即可查看>/LanguageWeb/src/com/language/action/ChooseAction.java
package com.language.action; import java.util.Hashtable; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class ChooseAction extends ActionSupport{ private Locale current; public void setCurrent(Locale cur) { this.current = cur; } @SuppressWarnings("unchecked") public Map getLocales() { Map locales =new Hashtable(4); ResourceBundle bundle = ResourceBundle.getBundle("globalMessages" , current); locales.put(bundle.getString("language.en"), Locale.US); locales.put(bundle.getString("language.zh"), Locale.CHINA); locales.put(bundle.getString("language.ja"), Locale.JAPAN); return locales; } public String execute(){ return "success"; } public String toIndex(){ return "index"; } public String getSuccess(){ ActionContext ac=ActionContext.getContext(); ac.put("tip", getText("language.success")); return "index"; } }
最近下载更多