美文网首页
解决Servlet中文乱码的问题

解决Servlet中文乱码的问题

作者: ekou | 来源:发表于2018-10-08 11:24 被阅读0次

    在Servlet中,你的数据获取到了,但是中文是“?”,出现一个输出中文乱码的问题,把下面三行代码加上就可以了

    protected void doPost(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    request.setCharacterEncoding("utf-8");//1

    response.setContentType("text/html;charset=utf-8");//2

    response.setCharacterEncoding("utf-8"); //3

    HandleImpl xm = new HandleImpl();

    List list = xm.getStudentes();

    JSONArray json=JSONArray.fromObject(list);

    PrintWriter out = response.getWriter();

    out.println(json);

    out.flush();

    out.close();

    }---------------------本文来自 听雨季节 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/qq_30072293/article/details/76976130?utm_source=copy

    相关文章

      网友评论

          本文标题:解决Servlet中文乱码的问题

          本文链接:https://www.haomeiwen.com/subject/eqbdaftx.html