Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 

Unzip servlet Java code example - Click here to copy ->>>

   Can't find what you're looking for? Try our search:

Really working examples categorized by API, package, class. You can compile and run our examples right away! Not from source code for Java projects - only working examples! Copy, compile and run!
------------------

Code:

 
 import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.util.zip.*;

public class unzip extends HttpServlet
{
public void service( HttpServletRequest _req, HttpServletResponse _res)
throws ServletException, IOException
     {
          String strArchive = _req.getParameter( "archive" );
          String strFile = _req.getParameter( "file" );
          if ( strArchive != null && strArchive.length() != 0 &&
                strFile != null && strFile.length() != 0 )
          {
               unzipFile( _req.getRealPath(strArchive), strFile, _res );
          }
          else
               _res.setStatus( HttpServletResponse.SC_NO_CONTENT );
     }

     private void unzipFile( String _strArchive, String _file,
HttpServletResponse _res ) throws IOException
     {
          ZipFile zF = new ZipFile( _strArchive );

          ZipEntry zE = zF.getEntry( _file.toUpperCase() );

          _res.setContentType( "text/html" );
          PrintStream    Out = new PrintStream( _res.getOutputStream() );
          DataInputStream In = new DataInputStream( zF.getInputStream( zE ) );

          String LineIn;
          while ( (LineIn=In.readLine()) != null )
               Out.println( LineIn );

          zF.close();
          Out.flush();
     }
}

/**
*   Java Servlets by Example
*   Alan R. Williamson
*   http://manning.com/books/williamson
*   ISBN: 188477766X
*/

 
 



References.

The list of classes which were used on this page you can find below. The links to Java API contain official SUN documentation about all used classes.

  java.util.zip.ZipFile

  java.io.IOException

  java.util.zip.ZipEntry

  java.io.PrintStream

  java.io.DataInputStream




[ Go Back ]



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy