我正在尝试使用 Java 过滤器更改区域设置,但以下代码不起作用,因为 JSP 页面仍以英语呈现:
public class PreferenceFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
Locale locale = StringUtils.parseLocaleString("fr");
res.setLocale(locale);
chain.doFilter(req, res);
}
}
我也在使用 Spring MVC,我们正在使用自己的翻译系统来获取不同语言环境的翻译:
<bean id="messageSource"
class="com.mycompany.web.translations.DatabaseDrivenMessageSourceImpl" scope="singleton">
<property name="cacheSeconds" value="3"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>