protected String setupCharacterEncoding(String mimeType, HttpServletRequest request, HttpServletResponse response) { final String characterEncoding = MIMEMapping.getContentEncodingOrDefault(mimeType); try { // let's not override the request encoding if set by the servlet container or the requesting browser if (request.getCharacterEncoding() == null) { request.setCharacterEncoding(characterEncoding); } } catch (UnsupportedEncodingException e) { log.error("Can't set character encoding for the request (mimetype={})", mimeType, e); } response.setCharacterEncoding(characterEncoding); return characterEncoding; }
@Override public void handle(HttpServletRequest request, HttpServletResponse response) { try { if (!response.isCommitted()) { response.setHeader("WWW-Authenticate", "FormBased"); response.setContentType("text/html"); if (null == request.getCharacterEncoding()) { response.setCharacterEncoding(MIMEMapping.getContentEncodingOrDefault("text/html")); } } freemarkerHelper.render(getLoginForm(), getTemplateContext(), response.getWriter()); } catch (Throwable t) { log.error("exception while writing login template", t); } }