Unzip servlet 1.4


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 the following parameters to this servlet:

file - describes your jar/zip file
path - describes a path for the resource to be extracted
type - Optional parameter. Describes a content type. By default it will be defined by the extracted resource

You can set also an optional initial parameter expires. This parameter describes a caching time (in seconds) for the images (client side cache).

For example here we are extracting image from the archive:
 


   <img src="http://your_host/servlet/Unzip?file=/WEB-INF/myfile.jar&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"/>

 

Alternatively, you can define path via mapping. Set zip (jar) file as an initial parameter and define mapping for files you need to unzip:
 


    <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>


 


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

then
 


   <img src="http://your_host/pic/a.gif"/>

 

will unzip /pic/a.gif from your archive (/WEB-INF/myfile.jar in this example) on the fly.
 

    For downloading:   unzipPackage.jar
 

 © Coldbeans     Comments ?
 

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

Also in Coldtags: