Static file servlet v. 1.2


This component lets you optimize static files downloading on Java servers like Tomcat. For example, rather than serve static files (e.g. favicon, background etc.) with default Tomcat servlet you can read the whole file once during the first request and return its content right from the memory after that. In the high load systems it saves a lot of server's resources actually. How to use it:

1) download staticfilePackage.jar and save it in WEB-INF/lib

2) describe StaticFile servlet in web.xml file. You have to provide an initial parameter - file for the processing. An optional parameter mime lets you define mime type settings for your file. By default servlet calculates mime type depends on file extension.  


    <servlet>
     <servlet-name>StaticFile</servlet-name>
     <servlet-class>com.jsos.statfile.StaticFileServlet</servlet-class>
     <init-param>
      <param-name>file</param-name>
      <param-value>path_for_your_file</param-value>
     </init-param>
    </servlet>

E.g. for favicon file:  


    <servlet>
     <servlet-name>StaticFile</servlet-name>
     <servlet-class>com.jsos.statfile.StaticFileServlet</servlet-class>
     <init-param>
      <param-name>file</param-name>
      <param-value>/favicon.ico</param-value>
     </init-param>
    </servlet>

3) define a mapping. E.g. for your favicon
 


    <servlet-mapping>
     <servlet-name>StaticFile</servlet-name>
     <url-pattern>/favicon.ico</url-pattern>
    </servlet-mapping>

and now the described file will be cached and served from the memory. And for the several static files just repeat this description several times with the different names. Actually this component works as a constant cache for the default servlet.

For downloading:

servlet: staticfilePackage.jar  
 

 © Coldbeans    Comments?
 

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

     

Also in JSOS: