List of usage examples for javax.servlet ServletResponse setCharacterEncoding
public void setCharacterEncoding(String charset);
From source file:com.flexive.war.filter.FxRequestUtils.java
/** * Set the request and response character encodings to UTF-8 if they are not so already. * Either of the parameters may be set to null, in this case no action is performed. * * @param request the servlet request//from w ww.j ava2 s . c o m * @param response the servlet response */ public static void setCharacterEncoding(ServletRequest request, ServletResponse response) { if (request != null && !"UTF-8".equals(request.getCharacterEncoding())) { try { request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } } if (response != null && !"UTF-8".equals(response.getCharacterEncoding())) { response.setCharacterEncoding("UTF-8"); } }
From source file:com.blacklocus.webapp.app.StaticResourceUTF8CharEncodingFilterHolder.java
public StaticResourceUTF8CharEncodingFilterHolder() { super(new Filter() { @Override/*from w ww .j a va 2 s. c om*/ public void init(FilterConfig filterConfig) throws ServletException { // no-op } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { response.setCharacterEncoding(CharEncoding.UTF_8); chain.doFilter(request, response); } @Override public void destroy() { // no-op } }); }
From source file:com.netsteadfast.greenstep.base.filter.CharsetFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { response.setContentType(this.contentType); response.setCharacterEncoding(this.encoding); chain.doFilter(request, response);//ww w . j av a2 s. c om }
From source file:org.agnitas.web.filter.CharacterEncodingFilter.java
/** * executes this filter//w ww . j a v a2 s . co m */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { request.setCharacterEncoding(encoding); response.setCharacterEncoding(encoding); chain.doFilter(request, response); response.setCharacterEncoding(encoding); }
From source file:net.duckling.ddl.web.filter.VWBFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { request.setCharacterEncoding(encoding); response.setCharacterEncoding(encoding); if (request instanceof HttpServletRequest) { findTeam((HttpServletRequest) request); filterChain.doFilter(request, response); VWBContext.setCurrentTid(-1);//from w w w . j av a 2 s . com } }
From source file:org.mifos.servlet.filters.CharacterEncodingFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding(CharEncoding.UTF_8); response.setCharacterEncoding(CharEncoding.UTF_8); if (!CharEncoding.UTF_8.equals(response.getCharacterEncoding())) { // MIFOS-5435 - the character encoding was not set because the connection is in including state try {// w ww .j av a 2 s .c o m Method getResponse = response.getClass().getMethod("getResponse"); ServletResponse servletResponse = (ServletResponse) getResponse.invoke(response); getResponse = servletResponse.getClass().getMethod("getResponse"); ServletResponse jettyResponse = (ServletResponse) getResponse.invoke(servletResponse); Field _characterEncoding = jettyResponse.getClass().getDeclaredField("_characterEncoding"); _characterEncoding.setAccessible(true); _characterEncoding.set(jettyResponse, CharEncoding.UTF_8); } catch (NoSuchFieldException e) { logger.debug(e); } catch (IllegalAccessException e) { logger.debug(e); } catch (NoSuchMethodException e) { logger.debug(e); } catch (InvocationTargetException e) { logger.debug(e); } } chain.doFilter(request, response); }
From source file:com.netsteadfast.greenstep.sys.GreenStepBaseFormAuthenticationFilter.java
protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException { if (isAjaxRequest((HttpServletRequest) request)) { response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); response.getWriter().write(Constants.NO_LOGIN_JSON_DATA); return;/* w w w. j a v a2 s. co m*/ } if (this.isDojoxContentPane((HttpServletRequest) request)) { // dojox.layout.ContentPane ??? login.action ?? WebUtils.issueRedirect(request, response, Constants.DOJOX_CONTENT_PANE_XHR_RE_LOGIN_PAGE); return; } WebUtils.issueRedirect(request, response, getLoginUrl()); }
From source file:net.ymate.platform.mvc.web.DispatcherFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // ?//www .j a v a 2 s. c o m request.setCharacterEncoding(WebMVC.getConfig().getCharsetEncoding()); response.setCharacterEncoding(WebMVC.getConfig().getCharsetEncoding()); response.setContentType("text/html;charset=" + WebMVC.getConfig().getCharsetEncoding()); // IWebRequestContext _context = __dispHelper.bindRequestContext((HttpServletRequest) request); if (null == ignorePatern || !ignorePatern.matcher(_context.getUrl()).find()) { __dispHelper.doRequestProcess(_context, __filterConfig.getServletContext(), (HttpServletRequest) request, (HttpServletResponse) response); } else { chain.doFilter(request, response); } }
From source file:com.netsteadfast.greenstep.sys.GreenStepMobileFormAuthenticationFilter.java
protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException { if (isAjaxRequest((HttpServletRequest) request)) { response.setCharacterEncoding(Constants.BASE_ENCODING); response.setContentType("application/json"); response.getWriter().write(Constants.NO_LOGIN_JSON_DATA); return;// w w w. ja v a 2 s .c o m } if (this.isIframeMode((HttpServletRequest) request)) { // iframe ??? login.action ? WebUtils.issueRedirect(request, response, "/pages/system/error_static.jsp"); return; } if (this.isDojoxContentPane((HttpServletRequest) request)) { // dojox.layout.ContentPane ??? login.action ?? WebUtils.issueRedirect(request, response, Constants.DOJOX_CONTENT_PANE_XHR_RE_LOGIN_PAGE); return; } WebUtils.issueRedirect(request, response, getLoginUrl()); }
From source file:net.ymate.module.webproxy.support.DispatchProxyFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding(__charsetEncoding); response.setCharacterEncoding(__charsetEncoding); ///* w ww.j a va 2 s .co m*/ response.setContentType( Type.ContentType.HTML.getContentType().concat("; charset=").concat(__charsetEncoding)); // HttpServletRequest _request = new RequestMethodWrapper((HttpServletRequest) request, __requestMethodParam); HttpServletResponse _response = (HttpServletResponse) response; IRequestContext _requestContext = new DefaultRequestContext(_request, __requestPrefix); if (null == __ignorePatern || !__ignorePatern.matcher(_requestContext.getOriginalUrl()).find()) { if (StringUtils.isNotBlank(__prefix) && !StringUtils.startsWith(_requestContext.getRequestMapping(), __prefix) || __doMatchBlacklist(_requestContext.getRequestMapping())) { _response = new GenericResponseWrapper(_response); GenericDispatcher.create(WebMVC.get()).execute(_requestContext, __filterConfig.getServletContext(), _request, _response); } else { try { YMP.get().getEvents() .fireEvent(new WebProxyEvent(WebProxy.get(), WebProxyEvent.EVENT.REQUEST_RECEIVED) .addParamExtend(IEvent.EVENT_SOURCE, _requestContext)); // String _requestMapping = _requestContext.getRequestMapping(); if (StringUtils.isNotBlank(__prefix)) { _requestMapping = StringUtils.substringAfter(_requestMapping, __prefix); } StringBuilder _url = new StringBuilder(WebProxy.get().getModuleCfg().getServiceBaseUrl()) .append(_requestMapping); if (Type.HttpMethod.GET.equals(_requestContext.getHttpMethod())) { if (StringUtils.isNotBlank(_request.getQueryString())) { _url.append("?").append(_request.getQueryString()); } } WebProxy.get().transmission(_request, _response, _url.toString(), _requestContext.getHttpMethod()); } catch (Throwable e) { _LOG.warn("An exception occurred: ", RuntimeUtils.unwrapThrow(e)); } finally { YMP.get().getEvents() .fireEvent(new WebProxyEvent(WebProxy.get(), WebProxyEvent.EVENT.REQUEST_COMPLETED) .addParamExtend(IEvent.EVENT_SOURCE, _requestContext)); } } } else { chain.doFilter(_request, _response); } }