views:

515

answers:

2

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

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?

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 );

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

Any advices on this?

+1  A: 

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 ?

krosenvold