출처 : http://stackoverflow.com/questions/2876250/tomcat-cache-control
http://blog.naver.com/mankeys/220219120741
css, image 등을 바꾸었는데 바로 반영이 안되서 안타까울때 다음과 같이 캐쉬 컨트롤을 하자 .
1. CacheControlFilter class
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
public class CacheControlFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse resp = (HttpServletResponse) response;
resp.setHeader("Expires", "Tue, 03 Jul 2001 06:00:00 GMT");
// resp.setDateHeader("Last-Modified", new Date());
resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
resp.setHeader("Pragma", "no-cache");
chain.doFilter(request, response);
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
2. web.xml
<filter>
<filter-name>SetCacheControl</filter-name>
<filter-class>com.lm.util.CacheControlFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SetCacheControl</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
그러면 다음과 같이 설정이 바뀌고 브라우저 캐쉬가 없어 진다.
'리눅스' 카테고리의 다른 글
서버용량 확인 (0) | 2016.06.21 |
---|---|
[error]Received fatal alert: handshake_failure through SSLHandshakeException (0) | 2016.01.11 |
java 버전 관리하기(alternatives) (0) | 2016.01.11 |
java 버전 업데이트하기 (0) | 2016.01.11 |
cron (리눅스 배치) (0) | 2015.10.05 |