I'm not sure exactly what you're trying to do, but yes, I've
successfully used JServ and the java.util.zip classes.  The
java.util.zip classes let you generate a ZIP file.  This has nothing to
do with bandwidth constraints... you won't be able to send standard web
pages it some magically compressed format that the browser will
understand.  The browser will get a zip file, and ask you to save it to
disk, or open winzip or something like that.

What I did was I needed to generate zip files for a data file.  I would
create a zip file, set the content type on the response to
application/x-zip-compressed, set the Content-Disposition header so I
could return a .zip file name instead of the .jsp I was using to
generate the file, created a ZipOutputStream around the
response.getOutputStream, and created a zip which was automatically sent
to the server.  My code looked something like this...

Note that this servlet was actually used with servlet chaining (I think
one of the best reasons to use servlet chaining).  I could return the
data as raw data, or I could set the content type of that data to be my
lokitech/zip-it mime type, and the servlet engine would in turn run this
zip filter code... (admitedly, I'm probably confusing people more than
I'm helping at this point, but hopefully you'll understand both issues)

------------

response.setContentType ("application/x-zip-compressed");
if (request.getHeader ("Content-Disposition") != null)
        response.setHeader ("Content-Disposition", request.getHeader
("Content-Disposition"));

DataInputStream in = new DataInputStream (request.getInputStream ());
ZipOutputStream zout = new ZipOutputStream (response.getOutputStream
());
zout.setMethod (ZipOutputStream.DEFLATED);
zout.setLevel (Deflater.BEST_COMPRESSION);

String line;
while ((line = in.readLine ()) != null)
{
        if (line.length () == 0)
                continue;

        //line contains the name of the file
        ZipEntry entry = new ZipEntry (line);
        zout.putNextEntry (entry);

        PrintStream pout = new PrintStream (zout);
        while ((line = in.readLine ()) != null)
        {
                if (line.equals ("<EOF>"))
                        break;
                pout.println (line);
        }
        zout.closeEntry ();
}
zout.finish ();
-----------

Hope this helps.  Actually, I did have *another* servlet chaining idea
called RemoveWhitespace, which would filter out all unnecessary
whitespace in a web page.  This was great because as we were developing,
we could see very nicely formatted HTML, but then when we went to
deliver this in production, we'd apply this filter and save 10-15% space
per page.  Normally that's not a big deal, but this was on a "web-CD"
where the more space we could save meant more space for
products/advertisers, so there was real financial incentives.

Serge Knystautas
Loki Technologies
http://www.lokitech.com


----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to