Jetty response character encoding

前端 未结 5 2093
旧时难觅i
旧时难觅i 2021-01-13 03:46

How do I set the default character encoding on my responses to UTF-8?

I\'ve tried this

    System.setProperty(\"file.encoding\", \"UTF-8\");
<         


        
5条回答
  •  星月不相逢
    2021-01-13 04:29

    I created character encoding filter to one legacy application.

    public class CharacterEncodingFilter implements Filter {
    
        @Override
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
            if(req instanceof Request){             
                req.setCharacterEncoding("UTF-8");
            }
            chain.doFilter(req, res);
        }
    
        @Override
        public void init(FilterConfig arg0) throws ServletException {
        }
    
        @Override
        public void destroy() {
        }
    }
    

    In web.xml filter-mapping has the url-pattern of /*. This routes all requests from the web application through the CharacterEncodingFilter.

    
        CharacterEncoding
        CharacterEncoding
        my.app.filter.CharacterEncodingFilter
    
    
        CharacterEncoding
        /*
    
    

提交回复
热议问题