예제 #1
0
  @Override
  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
      throws IOException, ServletException {

    req.setCharacterEncoding("UTF-8");
    res.setCharacterEncoding("UTF-8");

    HttpServletRequest httpReq = (HttpServletRequest) req;
    String lang = httpReq.getParameter("lang");
    if (lang != null && !lang.isEmpty()) {
      ThreadLocalLocaleHolder.set(new Locale(lang));
    } else if ((lang = (String) httpReq.getSession().getAttribute("lang")) != null) {
      ThreadLocalLocaleHolder.set(new Locale(lang));
    }
    httpReq.getSession().setAttribute("lang", ThreadLocalLocaleHolder.get().getLanguage());

    chain.doFilter(req, res);
  }