Im using intellij idea and tomcat 8 and here is my filter:
@WebFilter(urlPatterns = { "/*" }, initParams = {@WebInitParam(name = "encoding", value = "UTF-8", description = "Encoding Param") })
public class EncodingFilter implements Filter {
private String code;
public void init(FilterConfig filterConfig) throws ServletException {
code = filterConfig.getInitParameter("encoding");
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
String codeRequest = servletRequest.getCharacterEncoding();
if (code != null && !code.equalsIgnoreCase(codeRequest)) {
servletRequest.setCharacterEncoding(code);
servletResponse.setCharacterEncoding(code);
}
filterChain.doFilter(servletRequest, servletResponse);
}
public void destroy() {
code = null;
}
}
I dont understand why, but it doesnt work, when I'm putting english words everithing is ok, but when I'm putting russian letters to form, here is how it looks like:
String address = request.getParameter(PARAM_NAME_ADDRESS);
//**address : ЮзеÑова 12 144**
I have this in my jsp:
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" %>
What could be the problem?