Is there a way to use UTF-8 with app engine?

前端 未结 4 484
忘掉有多难
忘掉有多难 2020-12-10 03:06

I\'m looking for some explanation on how the app engine deals with character encodings. I\'m working on a client-server application where the server is on app engine.

<
4条回答
  •  春和景丽
    2020-12-10 03:59

    This is not specific to GAE, but in case you find it useful: I made my own filter:

    In web.xml

    
        charsetencoding
        mypackage.CharsetEncodingFilter
    
        ...
    
       charsetencoding
       /* 
    
    

    (place the filter-mapping fragment quite at the beginning of the filter-mappings, and check your url-pattern.

    And

    public class CharsetEncodingFilter implements Filter {
    
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            HttpServletRequest req = (HttpServletRequest) request;
            HttpServletResponse res = (HttpServletResponse) response;
            req.setCharacterEncoding("UTF-8");
            chain.doFilter(req, res);
            res.setCharacterEncoding("UTF-8");
        }
    
        public void destroy() { }
    
        public void init(FilterConfig filterConfig) throws ServletException { }
    }
    

提交回复
热议问题