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

旧城冷巷雨未停 提交于 2019-12-04 11:12:10

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/1906745/how-to-configure-cache-for-static-resources-in-web-xml-for-jetty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!