Use GZIP compression page

xiaoxiao2021-03-06  38

Gzip is GNU ZIP, many browsers support this compressed format Content, need to add response.addhead ("Content-Encoding", "gzip"); however, some unsupported browsers have an error, need to check Request.getHeaders ("accept-encoding"); whether GIZP is included.

The process of compression processing is processed in the filter chain, which is described in Web.xml of its own application:

gzipfilter

compressionFilters.comPressionFilter

gzipfilter

*. jsp

Here CompressionFilter is the class of the Filter interface, when implementing the DOFILTER method:

WrappedResponse = New CompressionServletResponseWrapper (httpservletResponse) response

Chain.dofilter (Request, WrappedRESPONSE);

In fact, using CompressionServletResponseWrapper to handle server-side response, we all know that the content of JSP display is generated by the OUT output in Response, then compressionServletResponseWrapper will complete the task under Gzip compression using the compressionServletResponseWrapper: compressionResponseSstream Stream = New compressionResponsestream (Response);

Pack OutputStream in CompressionResponsestream

GzipOutputStream GzipStream = New GzipOutputStream (Output);

Response.addheader ("Content-Encoding", "GZIP");

The specific code should also be found online.

转载请注明原文地址:https://www.9cbs.com/read-55657.html

New Post(0)