Cookbook-struts1.3.8案例分析-Localization
Cookbook-struts1.3.8案例分析-Localization
l Localization
Jsp頁面
<html:link page="/processLocalization.do">Default</html:link> <html:link page="/processLocalization.do?language=en">English</html:link> <html:link page="/processLocalization.do?language=en&country=CA">English (Canadian)</html:link> <html:link page="/processLocalization.do?language=en&country=US">English (US)</html:link> <html:link page="/processLocalization.do?language=en&country=GB">English (British)</html:link> <html:link page="/processLocalization.do?language=fr">French</html:link> <html:link page="/processLocalization.do?language=de">German</html:link> <html:link page="/processLocalization.do?language=es">Spanish</html:link> <html:link page="/processLocalization.do?language=it" lang="it" dir="ltr">Italian</html:link> <html:link page="/processLocalization.do?language=pt" lang="pt" dir="ltr">Portuguese</html:link> |
Action
public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need HttpSession session = request.getSession(); // Get locale from request, if any Locale locale = request.getLocale(); // If supplied, set Locale based on request parameters; // country and language String language = request.getParameter("language"); String country = request.getParameter("country"); if ((language != null && language.length() > 0) && (country != null && country.length() > 0)) { locale = new java.util.Locale(language, country); } elseif (language != null && language.length() > 0) { locale = new java.util.Locale(language, ""); } //Save locale session.setAttribute(Globals.LOCALE_KEY, locale); // Forward to result page return mapping.findForward("success"); } |
posted on 2008-07-08 02:17 MingIsMe 閱讀(66) 評論(0) 編輯 收藏 所屬分類: 16 案例分析