Google
 
Web unafbapune.blogspot.com

Friday, January 06, 2006

 

Control browser caching from jsp

The trick is to do it via http:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
long time = ... // get the file last modified or deployment time.
response.setDateHeader("Last-Modified", time);
%>
<c:choose>
<c:when test='${empty header["If-Modified-Since"]}'>
<%
System.out.println("Reponding with full content.");
%>
</c:when>
<c:otherwise>
<%
// check the If-Modified-Since against some value...
System.out.println("Setting not modified status");
response.setStatus(javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED);
%>
</c:otherwise>
</c:choose>

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?