package com.sky.struts.action;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
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 I18NAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm f,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String country = request.getParameter("country");
String language = request.getParameter("language");
Locale locale = request.getLocale();
if(country!=null&&!country.equals("")&&language!=null&&!language.equals("")){
System.out.println("--------------enter");
locale = new Locale(language,country);
}
HttpSession session = request.getSession();
session.setAttribute(Globals.LOCALE_KEY, locale);
return mapping.findForward("login");
}
}
jsp文件
<a href = "/project/i18n.do?country=CN&language=ch"> chinese</a>|
<a href = "/project/i18n.do?country=US&language=en"> English</a>
struts-config.xml
<action
path="/i18n"
scope="request"
type="com.amaker.struts.action.I18NAction" >
<forward name="login" path="/login.jsp"></forward>
</action>