List of usage examples for javax.servlet ServletResponse setCharacterEncoding
public void setCharacterEncoding(String charset);
From source file:com.scooterframework.web.controller.ScooterRequestFilter.java
/** * Time the processing that is performed by all subsequent filters in the * current filter stack, including the ultimately invoked servlet. * * @param request The servlet request we are processing * @param chain The filter chain we are processing * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs *//* ww w. j a v a 2s.c om*/ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean staticContent = isStaticContentRequest((HttpServletRequest) request); if (encoding != null) { request.setCharacterEncoding(encoding); if (!staticContent) { response.setCharacterEncoding(encoding); } } // boolean skip = skippedRequestPath((HttpServletRequest)request); boolean skip = staticContent; long before = System.currentTimeMillis(); if (!skip) { initializeActionContext((HttpServletRequest) request, (HttpServletResponse) response); } else { request.setAttribute(Constants.SKIP_PATH, "Y"); } if (isAjaxRequest((HttpServletRequest) request)) { request.setAttribute(Constants.SITEMESH_FILTERAPPLIED, Boolean.TRUE); } String requestPathKeyWithQueryString = requestInfo(skip, (HttpServletRequest) request); log.debug("============>>\"" + requestPathKeyWithQueryString + "\""); try { chain.doFilter(request, response); } catch (Throwable ex) { log.error("Error from chain.doFilter: " + ex.getMessage(), ex); } long after = System.currentTimeMillis(); if (EnvConfig.getInstance().allowRecordBenchmark()) { log.info("\"" + requestPathKeyWithQueryString + "\" takes: " + (after - before) + " ms"); if (EnvConfig.getInstance().allowRecordBenchmarkInHeader()) { HttpServletResponseWrapper resw = new HttpServletResponseWrapper((HttpServletResponse) response); resw.addHeader("Exec-Time", (after - before) + " ms"); } } clearCachedRequestData(); }
From source file:com.github.safrain.remotegsh.server.RgshFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; req.setCharacterEncoding(charset);/* w w w .j a va 2 s. c o m*/ resp.setCharacterEncoding(charset); if ("GET".equals(request.getMethod())) { String res = request.getParameter("r"); if (res != null && !res.isEmpty()) { if ("install".equals(res)) { performInstall(request, response); } else if ("shell".equals(res)) { performStartShell(request, response); } else if ("jar".equals(res)) { performJar(response); } else if ("rgsh".equals(res)) { performRgsh(request, response); } } else { performWelcomeScreen(request, response); } } else if ("POST".equals(request.getMethod())) { String sid = request.getParameter("sid"); if (sid != null && !sid.isEmpty()) { performShellExecute(request, response); } else { performRunScript(request, response); } } }
From source file:org.soaplab.clients.spinet.filters.DefaultFilter.java
/************************************************************************* * *************************************************************************/ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String servletPath = ((HttpServletRequest) request).getServletPath(); // log.info ("ServletPath: " + servletPath); // log.info ("RealPath: " + servletContext.getRealPath (servletPath)); // log.info ("MimeType: " + servletContext.getMimeType (servletContext.getRealPath (servletPath))); String mimeType = servletContext.getMimeType(servletContext.getRealPath(servletPath)); if (mimeType == null) { response.setContentType("text/plain"); }/*from www . j a va 2 s . co m*/ response.setCharacterEncoding("UTF-8"); defaultRequestDispatcher.forward(request, response); }
From source file:ro.cs.cm.web.filter.GeneralFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) res; // set the provided HTTP response parameters for (Enumeration<String> e = fc.getInitParameterNames(); e.hasMoreElements();) { String headerName = (String) e.nextElement(); response.addHeader(headerName, fc.getInitParameter(headerName)); }/*w w w. j av a 2s. co m*/ interceptLanguagePreference((HttpServletRequest) req); log(req); // setam enconding pentru request req.setCharacterEncoding(CHAR_ENCODING); // setam si encoding pentru response res.setCharacterEncoding(CHAR_ENCODING); chain.doFilter(req, response); }
From source file:ro.cs.om.web.filter.GeneralFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { logger.debug("doFilter - START - xxxxx "); HttpServletResponse response = (HttpServletResponse) res; // set the provided HTTP response parameters for (Enumeration<String> e = fc.getInitParameterNames(); e.hasMoreElements();) { String headerName = (String) e.nextElement(); response.addHeader(headerName, fc.getInitParameter(headerName)); }/*www. j a v a 2 s . c o m*/ interceptLanguagePreference((HttpServletRequest) req); log(req); // setam enconding pentru request req.setCharacterEncoding(CHAR_ENCODING); // setam si encoding pentru response res.setCharacterEncoding(CHAR_ENCODING); chain.doFilter(req, response); logger.debug("doFilter - END - xxxxx "); }
From source file:com.github.diluka.dynamic.web.staticizer.filter.DynamicWebStaticizerFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { for (IStaticizeDecider decider : deciders) { if (request instanceof HttpServletRequest) { HttpServletRequest req = (HttpServletRequest) request; CacheHttpServletResponseWrapper chsrw = new CacheHttpServletResponseWrapper( (HttpServletResponse) response); if (decider.decide(req)) { File html = prepareStaticPage(decider, req); if (html != null) { response.setCharacterEncoding("utf-8"); BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(html), "utf-8")); String s = reader.readLine(); while (s != null) { response.getWriter().write(s); s = reader.readLine(); }//from w w w . jav a 2 s .c o m reader.close(); return; } else { chain.doFilter(request, chsrw); saveHtmlFile(decider, req, chsrw); return; } } } } chain.doFilter(request, response); }
From source file:com.adanac.module.blog.filter.DynamicFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String requestUri = StringUtil.replaceSlants(((HttpServletRequest) request).getRequestURI()); try {/*from w ww .ja v a 2s .c o m*/ Map<String, Object> data = FreemarkerHelper .buildCommonDataMap(FreemarkerHelper.getNamespace(requestUri), ViewMode.DYNAMIC); boolean forbidden = loginFilter(data, requestUri, request); if (forbidden) { ((HttpServletResponse) response).sendError(HttpServletResponse.SC_FORBIDDEN); return; } String template = putCustomData(data, requestUri, request, response); response.setCharacterEncoding("UTF-8"); FreemarkerHelper.generateByTemplatePath(template + ".ftl", response.getWriter(), data); } catch (Exception e) { throw new RuntimeException(requestUri, e); } }
From source file:org.codelabor.system.web.filter.EncodingFilter.java
@Override public void preprocessFilterChain(ServletRequest request, ServletResponse response) throws IOException, ServletException { String requestBeforeEncoding = request.getCharacterEncoding(); String responseBeforeEncoding = response.getCharacterEncoding(); if (encoding.equalsIgnoreCase(requestBeforeEncoding)) { logger.debug("request character encoding: {}", encoding); } else {// w w w. j a va 2 s .c o m request.setCharacterEncoding(encoding); String requestAfterEncoding = request.getCharacterEncoding(); logger.debug("request character encoding: {} -> {}", requestBeforeEncoding, requestAfterEncoding); } if (encoding.equalsIgnoreCase(responseBeforeEncoding)) { logger.debug("response character encoding: {}", encoding); } else { response.setCharacterEncoding(encoding); String responseAfterCharacterEncoding = response.getCharacterEncoding(); logger.debug("response character encoding: {} -> {}", responseBeforeEncoding, responseAfterCharacterEncoding); } }
From source file:org.qifu.sys.GreenStepBaseFormAuthenticationFilter.java
protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException { if (!Constants.getSystem().equals(Constants.getMainSystem()) && !isAjaxRequest((HttpServletRequest) request)) { // ? core-web try {// w ww. j av a2 s. c om if (this.loginUseCurrentCookieForGeneralPackage(request, response)) { // no need to login-page String url = SimpleUtils.getHttpRequestUrl((HttpServletRequest) request); logger.warn("URL = " + url); WebUtils.issueRedirect(request, response, url); return; } } catch (Exception e) { e.printStackTrace(); } } if (isAjaxRequest((HttpServletRequest) request)) { response.setCharacterEncoding(Constants.BASE_ENCODING); response.setContentType("application/json"); response.getWriter().write(Constants.NO_LOGIN_JSON_DATA); return; } /* if (this.isIframeMode((HttpServletRequest)request)) { // iframe ??? login.action ? WebUtils.issueRedirect(request, response, "/pages/system/error_static.jsp"); return; } */ if (this.isTabPage((HttpServletRequest) request)) { // dojox.layout.ContentPane ??? login.action ?? WebUtils.issueRedirect(request, response, "/pages/system/login_again.jsp"); return; } WebUtils.issueRedirect(request, response, getLoginUrl()); }
From source file:no.sesat.search.http.filters.SiteLocatorFilter.java
private void doBeforeProcessing(final ServletRequest request, final ServletResponse response) throws IOException, ServletException { LOG.trace("doBeforeProcessing()"); final Site site = getSite(request); if (null != site) { request.setAttribute(Site.NAME_KEY, site); request.setAttribute("startTime", FindResource.START_TIME); MDC.put(Site.NAME_KEY, site.getName()); MDC.put("UNIQUE_ID", getRequestId(request)); /* Setting default encoding */ request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); } else {/* w ww . j a va 2 s . c o m*/ throw new ServletException("SiteLocatorFilter with no Site :-("); } }