response的OutputStream输出数据

<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"));
	}


你可能感兴趣的:(servlet)