File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Set Reponse Headers Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Set Reponse Headers Problem" Watch "Set Reponse Headers Problem" New topic
Author

Set Reponse Headers Problem

Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
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.


SCJP 1.2, SCWCD 1.4
Biba Basnetti
Greenhorn

Joined: Oct 09, 2006
Posts: 25
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

Joined: Nov 16, 2003
Posts: 164
You are wrong. It does have an effect. Looks like you need to study more.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set Reponse Headers Problem