• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Set Reponse Headers Problem

 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote the following filter and use it on WebLogic Server 8.1:



I want to set all HTTP responses with Cache-Control set to no-cache. For JSPs, it works ok.

For images and style sheets, the server will set the Last-Modified header again after I have set it to 1970. For Cache-Control, the server will remove it if it sets Last-Modified. It seems that Last-Modified and Cache-Control do not work together; you can only have one but not both.

What can I do? I want all responses to have Cache-Control set to no-cache. If Last-Modified is set, than Cache-Control is removed by server. I can't remove Last-Modified or change its value.
 
Biba Basnetti
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am studying for the SCWCD so maybe I don't know what the hell I am talking about but....


filterChain.doFilter(req, res);
if (res.containsHeader("Last-Modified")) {
res.setDateHeader("Last-Modified", 0);
}
res.setHeader("Cache-Control", "no-cache");


why are you calling the filterChain's doFilter method before you set the response headers? I think when you call the filterChain.doFilter() method the req,res goes through the filters stack and eventually to the servlet going to the browser. Setting the response headers after the filterChain.doFilter() should have no effect.
 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are wrong. It does have an effect. Looks like you need to study more.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic