1. 程式人生 > >response 以位元組流輸出

response 以位元組流輸出

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*
		 * 檢視String.getBytes(),原始碼,找到預設使用的碼錶
		 *  String csn = Charset.defaultCharset().name();
		 */
		String name = Charset.defaultCharset().name();
		System.out.println(name);
		
		//1. 指定瀏覽器看這份資料使用的碼錶
		response.setContentType("text/html;charset=GBK");
		
		//2. 指定輸出的中文用的碼錶
	    response.getOutputStream().write("我愛深圳黑馬訓練營..".getBytes("GBK"));//該處本環境預設為GBK,所以可以不用設定
	}