View Javadoc

1   package org.kuali.ole;
2   
3   
4   import javax.servlet.*;
5   import java.io.IOException;
6   
7   /**
8    * Created with IntelliJ IDEA.
9    * User: sm8451
10   * Date: 4/17/13
11   * Time: 11:38 AM
12   * To change this template use File | Settings | File Templates.
13   */
14  public class CharsetFilter implements Filter {
15  
16      private String encoding;
17  
18      public void init(FilterConfig config) throws ServletException {
19          encoding = config.getInitParameter("requestEncoding");
20          if (encoding == null) {
21              encoding = "UTF-8";
22          }
23      }
24  
25      public void doFilter(ServletRequest request, ServletResponse response, FilterChain next)
26              throws IOException, ServletException {
27          if (null == request.getCharacterEncoding()) {
28              request.setCharacterEncoding(encoding);
29          }
30          response.setContentType("text/html; charset=UTF-8");
31          response.setCharacterEncoding("UTF-8");
32          next.doFilter(request, response);
33      }
34  
35      public void destroy() {
36      }
37  
38  }
39