Example usage for javax.servlet ServletRequest setCharacterEncoding

List of usage examples for javax.servlet ServletRequest setCharacterEncoding

Introduction

In this page you can find the example usage for javax.servlet ServletRequest setCharacterEncoding.

Prototype

public void setCharacterEncoding(String env) throws UnsupportedEncodingException;

Source Link

Document

Overrides the name of the character encoding used in the body of this request.

Usage

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  ww  w  .  j  av  a2 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:org.beangle.web.filter.CharacterEncodingFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    request.setCharacterEncoding(encoding);
    chain.doFilter(request, response);//from   w  ww.j  a v a 2 s  .co m
}

From source file:org.agnitas.web.filter.CharacterEncodingFilter.java

/**
 * executes this filter//w  w  w .  j a  v a 2  s. c om
 */
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:com.zeperdi.demo.webapp.DemoFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    request.setCharacterEncoding(this.encoding);
    chain.doFilter(request, response);// ww  w .  j a v  a2 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 {/*from   www. ja va  2 s  .  c  om*/
            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:eionet.web.filter.ContentNegotiationFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    request.setCharacterEncoding("utf-8");

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    String requestUrl = httpRequest.getRequestURL().toString();

    if (!StringUtils.endsWithIgnoreCase(requestUrl, "/rdf")) {
        if (isRdfXmlPreferred(httpRequest)) {
            String redirectUrl = requestUrl + "/rdf";
            httpResponse.sendRedirect(redirectUrl);
            return;
        }/*from  w w  w.  j  a  v  a2 s  .  c  om*/
    }

    chain.doFilter(request, response);
}

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);//  w ww  . j  a v  a 2  s .  c om
    }
}

From source file:com.autentia.intra.filter.UTF8Filter.java

/**
 * Metemos en la request el formato de codificacion UTF-8
 *///from   w w w  . java2s  .  c  o m
public void doFilter(ServletRequest request, ServletResponse response, FilterChain fc)
        throws IOException, ServletException {
    response.setContentType(contentType);
    request.setCharacterEncoding(encoding);
    fc.doFilter(request, response);
}

From source file:net.ymate.platform.mvc.web.DispatcherFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    // ?// w  w w  . j a va 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:no.kantega.commons.filter.ParamEncodingFilter.java

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    if (((HttpServletRequest) servletRequest).getMethod().equals("POST")) {
        servletRequest.setCharacterEncoding(encoding);
    } else {/*from   w ww.  j a v a2  s .c  o m*/
        servletRequest.setCharacterEncoding(GETencoding);
    }
    for (String s : servletRequest.getParameterMap().keySet()) {
        servletRequest.getParameter(s);
    }

    filterChain.doFilter(servletRequest, servletResponse);
}