聊天室发送中文

写出来发现一个问题就是那个

我发中文乱码!!!!

是人都知道是utf-8的问题啦

但是,怎么搞?

我搞不出来

直接问人

原来要用一个过滤器

把发的信息过滤下来转成utf-8再发下去

public class Encoding implements Filter{
    private String encoding = "utf-8";

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding(encoding);
        response.setCharacterEncoding(encoding);
        chain.doFilter(request, response);
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        encoding = filterConfig.getInitParameter("encoding");
        if (encoding == null || encoding.trim().equals("")) {
            encoding = "utf-8";
        }
    }
}

谁有不用过滤器的方法?

求指导

原文地址:https://www.cnblogs.com/ydymz/p/6379549.html