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.
[ Go Back ]
|