一個GZIP編碼輸出問題

avaj發表於2008-01-18
如下程式碼為什麼什麼都顯示不出來呢,應該能列印出hello world的啊,但是顯示卻是 雪白一邊,這裡假設瀏覽器支援gzip編碼的,所以許多條件判斷就省去了,希望哪位達人能指點迷津啊,程式碼如下
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
OutputStream out = null;
response.setHeader("Content-Encoding", "GZIP");
out=new GZIPOutputStream(response.getOutputStream());
String content="hello world";
PrintWriter pw = new PrintWriter(out);
pw.println(content);
pw.flush();
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
doGet(request,response);
}

相關文章