Serve Gzipped content with Java Servlets

后端 未结 7 2259
予麋鹿
予麋鹿 2021-01-05 01:40

I was wondering if there was an easy way to serve GZipped content with Java Servlets. I already have the app up and running so the modifications needed should be to

7条回答
  •  萌比男神i
    2021-01-05 02:07

    Look at GzipOutputStream class. Something like this:

    response.setContentType(...)
    GzipOutputStream os = new GzipOutputStream(response.getOutputStream);
    //write to os
    Writer writer = new PrintWriter(os);
    

    Then use writer like you do usually.

提交回复
热议问题