如何防止嵌入式Jetty实例中缓存静态文件? [英] How to prevent caching of static files in embedded Jetty instance?

查看:141
本文介绍了如何防止嵌入式Jetty实例中缓存静态文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想防止CSS缓存在浏览器端.如何在嵌入式Jetty实例中做到这一点?

I want to prevent my CSSs from being cached on the browser side. How can I do it in embedded Jetty instance?

如果我使用的是xml配置文件,我会添加以下行:

If I were using xml configuration file, I would add lines like:

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

如何将其转换为代码?

How I can turn that into the code?

现在我以这种方式启动Jetty:

Right now I start Jetty this way:

BasicConfigurator.configure();

Server server = new Server();
SocketConnector connector = new SocketConnector();
// Set some timeout options to make debugging easier.
// 1 hour
connector.setMaxIdleTime( 1000 * 60 * 60 );
connector.setSoLingerTime( -1 );
connector.setPort( 8081 );
server.setConnectors( new Connector[] { connector } );

WebAppContext bb = new WebAppContext();
bb.setServer( server );
bb.setContextPath( "/" );
bb.setWar( "src/webapp" );

server.addHandler( bb );

我认为我应该在WebAppContext职责范围内的某个位置搜索setControlCache.

I think I should search setControlCache somewhere in the WebAppContext area of responsibility.

对此有何建议?

推荐答案

我通常使用ServletHolder,如下所示:

I normally use a ServletHolder, like this:

WebAppContext context = new WebAppContext();
ServletHolder servletHolder = new ServletHolder(MyServlet.class);
servletHolder.setInitParameter("cacheControl","max-age=0,public"); 
context.addServlet(servletHolder, "myservletpath");

虽然这与代码完全不匹配,但是您应该可以从那里找出答案?

While this does not exactly match your code you should be able to figure it out from there ?

这篇关于如何防止嵌入式Jetty实例中缓存静态文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆