response的OutputStream输出数据

来源:互联网 发布:中国食品安全数据 编辑:程序博客网 时间:2024/05/16 18:04
<span style="white-space:pre"></span>private void test1(HttpServletResponse response) throws IOException,UnsupportedEncodingException {//程序控制浏览器以什么码表打开response.setHeader("content-type", "text/html;charset=utf-8");String data = "天空空";OutputStream out = response.getOutputStream();//以什么编码打入out.write(data.getBytes("utf-8"));}

第二种

private void test2(HttpServletResponse response) throws IOException,UnsupportedEncodingException {String data = "天空空";OutputStream out = response.getOutputStream();//html: <meta>标签也能模拟响应头out.write("<meta http-equiv='content-type' content='text/html;charset=utf-8'>".getBytes());out.write(data.getBytes("utf-8"));}


0 0
原创粉丝点击