response的OutputStream输出数据

	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: 标签也能模拟响应头
		out.write("".getBytes());
		out.write(data.getBytes("utf-8"));
	}


你可能感兴趣的:(JavaEE)