response.setCharacterEncoding("UTF-8");
String encType = request.getHeader("Accept-Encoding"); if (encType != null && encType.contains("gzip")) { response.setHeader("Content-Encoding", "gzip"); } response.setCharacterEncoding("UTF-8");This code dynamically sets the character encoding based on the request header. If the request accepts gzip encoding, the response will be compressed using gzip. Otherwise, the response character encoding will be set to UTF-8. Package library: javax.servlet.http