public final class GzipFileServlet extends HttpServlet
Note, this servlet does not Gzip data, it only serves data that has already been gzip'ed.
To use, add something like the following to web.xml:
Then, in this example, one can say, in your HTML document:<servlet> <servlet-name>gzip</servlet-name> <servlet-class>fc.web.servlet.GzipFileServlet</servlet-class> </servlet> ... <!-- an example mapping, your taste may vary --> <servlet-mapping> <servlet-name>gzip</servlet-name> <url-pattern>/gzip</url-pattern> </servlet-mapping>
That will load the<html> <head> <title>Untitled</title> <script src="/gzip?js=myscript.js"></script> </head> <body> hello </body> </html>
myscript.js.gz
file (and if myscript.js.gz is not present, a servlet exception
will be logged). Note, the ".gz" extension is added automatically
if not specified in the filename.
There are two modes in serving files. In both cases, the file to be retrieved must already exist as a gzip file on the server.
text/html
or
text/javascript
/gzip?file=foo.html.gz&mimetype=text/html&encoding=ISO-8859-1
Absolute path names are like HTML absolute names and start from the document root directory of the web server.
Relative names (relative to the invoking page) are not supported by this servlet.
Constructor and Description |
---|
GzipFileServlet() |
Modifier and Type | Method and Description |
---|---|
void |
doGet(HttpServletRequest req,
HttpServletResponse res)
Returns the specified gzip file.
|
void |
init(ServletConfig conf) |
service
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
public GzipFileServlet()
public void init(ServletConfig conf) throws ServletException
init
in interface Servlet
init
in class GenericServlet
ServletException
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
doGet
in class HttpServlet
ServletException
java.io.IOException