使用Java Servlets提供Gzip压缩内容
问题描述:
我想知道是否有一种 easy 方式来使用Java Servlets提供GZipped内容。我已经启动并运行了应用程序,因此所需的修改应该太重了。
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 too heavy.
我可以在doPost / doGet方法结束时访问响应对象,所以我正在寻找像
I have access to the response object just at the end of the doPost/doGet method, so I'm looking for something like
response.setGzip(true);
它不一定那么简单但它会是理想的。
It doesn't have to be that easy but it would be ideal.
非常感谢
答
本文包含自动压缩的ServletFilter的完整(和简要)源代码在飞行中。
This article has the complete (and brief) source code for a ServletFilter that automatically compresses on the fly.