zoukankan      html  css  js  c++  java
  • servlet-向页面输出中文出现乱码处理方式

    package cn.lijun .content;

    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class TextServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    //设置response查询的码表
    //response.setCharacterEncoding("UTF-8");

    //通过一个头 Content-Type 告知客户端使用何种码表
    //response.setHeader("Content-Type", "text/html;charset=UTF-8");

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

    PrintWriter writer = response.getWriter();
    //writer.write("hello response!!!");
    writer.write("你好");

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    }
    }

  • 相关阅读:
    [hdu1402]A * B Problem Plus(NTT)
    拦截导弹问题(Noip1999)
    删数问题(Noip1994)
    1217:棋盘问题
    随笔功能测试
    教师派8
    教师派7
    教师派6
    教师派5
    教室派4
  • 原文地址:https://www.cnblogs.com/lijun6/p/10462672.html
Copyright © 2011-2022 走看看