Unzip servlet 1.1

It is a Java servlet allows you to work with your archives (jar/zip files). How to get JavaScript file packaged with your application? How to set reference to the packaged image file etc.? It is what Unzip servlet is for. Servlet lets you extract content from the archive and use extracted data in your JSP (HTML) files.

How to use it:

a) copy unzipPackage.jar into WEB-INF/lib

b) describe UnzipServlet in web.inf file.
 


    <servlet>
     <servlet-name>Unzip</servlet-name>
     <servlet-class>com.jsos.unzip.UnzipServlet</servlet-class>
    </servlet>

c) describe a mapping for this servlet:
 


   <servlet-mapping>
    <servlet-name>Unzip</servlet-name>
    <url-pattern>/servlet/Unzip</url-pattern>
   </servlet-mapping>

You must pass three parameters to this servlet:

file - describes your jar/zip file
path - describes a path for the resource to be extracted
type - describes a content type. By default it is text/html

For example here we are extracting image from the archive:
 


   <img src="http://your_host/servlet/Unzip?file=/WEB-INF/myfile.har&path=com/dir/myfile.gif&type=image/gif"/>

Any of the parameters can be described as an initial parameter for this servlet in web.xml. For example this definition describes a file parameter:
 


    <servlet>
     <servlet-name>Unzip</servlet-name>
     <servlet-class>com.jsos.unzip.UnzipServlet</servlet-class>
     <init-param>
      <param-name>file</param-name>
      <param-value>/WEB-INF/myfile.jar</param-value>
     </init-param>
    </servlet>

In this case you can write some like this in your JSP/HTML file:
 


   <img src="http://your_host/servlet/Unzip?path=com/dir/myfile.gif&type=image/gif"/>

 
 

    For downloading:   unzipPackage.jar
 

 © Coldbeans     Comments ?
 

See also JSOS - the largest collection of servlets and filters.