Features: Using Sevrlet bar data compression in the transfer to the foreground
Package cn.hncu.img;
Import Java.io.ByteArrayOutputStream;
Import java.io.IOException;
Import Java.io.OutputStream;
Import Java.io.PrintWriter;
Import Java.util.zip.GZIPOutputStream;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse; public class Gzipservlet extends HttpServlet {public void doget (HttpServletRequest request, HttpServletResponse Respo
NSE) throws Servletexception, IOException {doPost (request, response); /** * The DoPost method of the servlet.
<br> * * This are called when a form has it tag value method equals to post. * @param request the request send by the ' client to the ' server * @param response the response send by the Serv
ER to the client * @throws servletexception If a error occurred * @throws IOException if an error occurred */public void DopoSt (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {// Compresses data in byte array str into the BOS memory stream String str= "SSSDADASDASDASSSSDADASDASDA +" Ssssdadasdasdassssdadasdas
Dasss "+" Sdadasdasdassssdadasdasdassssdadasdasdas ";
Byte[] Buf=str.getbytes ();
System.out.println ("Buf-length:" +buf.length);
Bytearrayoutputstream bos=new Bytearrayoutputstream ();
Gzipoutputstream gout=new Gzipoutputstream (BOS);
Gout.write (BUF);
Gout.close ();
Take the compressed data out of the memory stream array byte Dest[]=bos.tobytearray ();
System.out.println ("Des-length:" +dest.length);
Response.setheader ("content-encoding", "gzip");/tell the browser that the content currently being sent is in gzip format response.setcontenttype ("text/html");
OutputStream Out=response.getoutputstream ();
Out.write (SRC);
Out.write (dest);
Out.flush ();
Out.close ();
}
}