public final class GzipFileServlet extends javax.servlet.http.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(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
Returns the specified gzip file.
|
void |
init(javax.servlet.ServletConfig conf) |
public GzipFileServlet()
public void init(javax.servlet.ServletConfig conf) throws javax.servlet.ServletException
init
in interface javax.servlet.Servlet
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
public void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException, IOException
doGet
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
IOException