Servlet for serving static content

前端 未结 14 1957
天命终不由人
天命终不由人 2020-11-22 06:02

I deploy a webapp on two different containers (Tomcat and Jetty), but their default servlets for serving the static content have a different way of handling the URL structur

14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 06:27

    I had the same problem and I solved it by using the code of the 'default servlet' from the Tomcat codebase.

    https://github.com/apache/tomcat/blob/master/java/org/apache/catalina/servlets/DefaultServlet.java

    The DefaultServlet is the servlet that serves the static resources (jpg,html,css,gif etc) in Tomcat.

    This servlet is very efficient and has some the properties you defined above.

    I think that this source code, is a good way to start and remove the functionality or depedencies you don't need.

    • References to the org.apache.naming.resources package can be removed or replaced with java.io.File code.
    • References to the org.apache.catalina.util package are propably only utility methods/classes that can be duplicated in your source code.
    • References to the org.apache.catalina.Globals class can be inlined or removed.

提交回复
热议问题