public class GZipFilter extends Object implements javax.servlet.Filter
<filter>
<filter-name>GZipFilter</filter-name>
<filter-class>org.josef.web.servlet.GZipFilter</filter-class>
<init-param>
<param-name>threshold</param-name>
<param-value>2048</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>GZipFilter</filter-name>
<url-pattern>/demo/*</url-pattern>
</filter-mapping>
Technical note: This filter does not use an annotation on purpose!
You probably want to configure the url pattern and determine the threshold for compression.
The threshold is optional and defaults to 1024 bytes (1K).
So every response larger than 1K is compressed while smaller ones are untouched.Constructor and Description |
---|
GZipFilter() |
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Destroys this filter by doing absolutely nothing.
|
void |
doFilter(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse,
javax.servlet.FilterChain filterChain)
Zips the response when the client accepts gzip encoding and the size of the response exceeds the threshold.
|
void |
init(javax.servlet.FilterConfig filterConfig)
Initializes this filter by getting the threshold init parameter.
|
public void init(javax.servlet.FilterConfig filterConfig)
init
in interface javax.servlet.Filter
filterConfig
- The Filter configuration.public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain) throws javax.servlet.ServletException, IOException
doFilter
in interface javax.servlet.Filter
servletRequest
- The servlet request.servletResponse
- The servlet response.filterChain
- The filter chain.javax.servlet.ServletException
- When another filter in the chain throws this exception.IOException
- When the response could not be written.public void destroy()
destroy
in interface javax.servlet.Filter
Copyright © 2008–2018. All rights reserved.