Skip to content

Instantly share code, notes, and snippets.

@ezhov-da
Last active March 10, 2019 12:22
Show Gist options
  • Save ezhov-da/fc65c62d601f58fcca4c6e71ebbe5c31 to your computer and use it in GitHub Desktop.
Save ezhov-da/fc65c62d601f58fcca4c6e71ebbe5c31 to your computer and use it in GitHub Desktop.
java servlet filter charset
[code:]java[:code] import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CharsetFilter implements Filter
{
// кодировка
private String encoding;
public void init(FilterConfig config) throws ServletException
{
// читаем из конфигурации
encoding = config.getInitParameter("requestEncoding");
// если не установлена — устанавливаем UTF-8
if( encoding==null ) encoding="UTF-8";
}
public void doFilter(ServletRequest request,
ServletResponse response, FilterChain next)
throws IOException, ServletException
{
request.setCharacterEncoding(encoding);
next.doFilter(request, response);
}
public void destroy(){}
}
}
[/code]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment