struts 1国際化の切り替え
18、strutsハードコーディングの国際化の基礎の上で、strutsの国際化の切替1を実現して、strutsのデフォルトを利用してlocaleをsessionの中に置く特性を理解して、プログラミングの方式の切替言語の設定を完成します*参照:ChangeLanguageAction.JAva 2、index.jspページに追加
33、ChageLanguageAction.java
4、struts-config.xml加入構成情報
http://www.cnblogs.com/jhlishero/archive/2009/08/27/1554928.html
<a href="changelang.do?lang=zh"> </a>
<a href="changelang.do?lang=en"> <a/>
33、ChageLanguageAction.java
package com.bjsxt.struts;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
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;
public class ChangeLanguageAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//
String lang = request.getParameter("lang");
// Locale
Locale currentLocale = Locale.getDefault();
if ("zh".equals(lang)) {
currentLocale = new Locale("zh", "CN");
}else if("en".equals(lang)) {
currentLocale = new Locale("en", "US");
}
// Action setLocale Locale
this.setLocale(request, currentLocale);
//
//request.getSession().setAttribute(Globals.LOCALE_KEY, currentLocale);
return mapping.findForward("index");
}
}
4、struts-config.xml加入構成情報
<action path="/changelang"
type="com.bjsxt.struts.ChangeLanguageAction"
>
<forward name="index" path="/index.jsp"/>
</action>
http://www.cnblogs.com/jhlishero/archive/2009/08/27/1554928.html