Last active
March 10, 2019 12:22
-
-
Save ezhov-da/fc65c62d601f58fcca4c6e71ebbe5c31 to your computer and use it in GitHub Desktop.
java servlet filter charset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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