Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure cache for static resources in web.xml for Jetty?

I was reading this: http://docs.codehaus.org/display/JETTY/LastModifiedCacheControl

It says

The Jetty default servlet allows the cache control header to be set for static content by using the cacheControl init parameter using:

<init-param>
    <param-name>cacheControl</param-name>
    <param-value>max-age=3600,public</param-value>
</init-param>

However, I am not sure that I am using the default servlet. At least such configuration is not in web.xml:

<web-app>
    <display-name>Wicket QuickStart</display-name>
    <context-param>
        <param-name>configuration</param-name>
        <param-value>development</param-value>
    </context-param>
    <servlet>
        <servlet-name>quickstart</servlet-name>
        <servlet-class>org.apache.wicket.protocol.http.WicketServlet</servlet-class>
        <init-param>
            <param-name>applicationClassName</param-name>
            <param-value>wicket.quickstart.WicketApplication</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>quickstart</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

I would like to configure cache for static resources such as:

/src/webapp/*, i.e.: /src/webapp/images, /src/webapp/css, /src/webapp/js, etc.

What should I add into my web.xml?

like image 828
Martin Avatar asked Dec 15 '09 11:12

Martin


1 Answers

Need to add the following to your web.xml

<servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class>
    <init-param>
        <param-name>cacheControl</param-name>
        <param-value>max-age=3600,public</param-value>
    </init-param>
</servlet>
like image 188
user5084 Avatar answered Oct 19 '22 04:10

user5084