Struts 1.2.1新特点简介(1)(详细情况可参考http://blog.csdn.net/kui/).............7、JA MailreaderStruts 1.2.1自带的例子Mailreader Example包含了日本资源文件,虽然我们不需要日本资源,但它对于我们学习如何实现“国际化信息”是非常有好处的,实现方式很简单,例如自带的例子welcome.jsp有如下语言类型选择:
<ul>
<li><html:link action="/Locale?language=en">English</html:link></li><li><html:link action="/Locale?language=ja" useLocalEncoding="true">Japanese</html:link></li><li><html:link action="/Locale?language=ru" useLocalEncoding="true">Russian</html:link></li></ul>在LocaleAction.java中进行处理:public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String language = request.getParameter(LANGUAGE); String country = request.getParameter(COUNTRY); Locale locale = getLocale(request); if ((!isBlank(language)) && (!isBlank(country))) { locale = new Locale(language, country); } else if (!isBlank(language)) { locale = new Locale(language, ""); } HttpSession session = request.getSession(); session.setAttribute(Globals.LOCALE_KEY, locale); String target = request.getParameter(PAGE); if (!isBlank(target)) return new ActionForward(target); target = request.getParameter(FORWARD); if (isBlank(target)) target = mapping.getParameter(); if (isBlank(target)) { log.warn(LOCALE_LOG); return null; } return mapping.findForward(target); }
<ul>
<li><html:link action="/Locale?language=en">English</html:link></li><li><html:link action="/Locale?language=ja" useLocalEncoding="true">Japanese</html:link></li><li><html:link action="/Locale?language=ru" useLocalEncoding="true">Russian</html:link></li></ul>在LocaleAction.java中进行处理:public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String language = request.getParameter(LANGUAGE); String country = request.getParameter(COUNTRY); Locale locale = getLocale(request); if ((!isBlank(language)) && (!isBlank(country))) { locale = new Locale(language, country); } else if (!isBlank(language)) { locale = new Locale(language, ""); } HttpSession session = request.getSession(); session.setAttribute(Globals.LOCALE_KEY, locale); String target = request.getParameter(PAGE); if (!isBlank(target)) return new ActionForward(target); target = request.getParameter(FORWARD); if (isBlank(target)) target = mapping.getParameter(); if (isBlank(target)) { log.warn(LOCALE_LOG); return null; } return mapping.findForward(target); }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货