tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Could you advice me to correct my custom tag code?
Date Wed, 02 Aug 2000 00:50:11 GMT
The code itself looks OK, but I have a couple comments and questions:

* In what way does this "not work properly"?  Is the problem that the
  headers are not getting generated, or that they are getting generated
  but the page is still cached?

* To answer the question above, you might need to use some sort of
  debugging tool that lets you look at the actual headers received
  (by the client) as part of the response.

* If this custom tag occurs in your page at a point such that the
  output response has been committed already (in other words,
  the first buffer-full of data has been sent), any later attempt to
  set HTTP headers will be ignored.  To avoid this, be sure that
  you specify a buffer size in the <%@ page %> directive big
  enough to ensure that this does not happen.

* I'm not sure you really need to go to the effort of checking which
  protocol the request came in with.  I tend to write all three of the
  following headers in my code when I want to defeat caching:
        res.addHeader("Pragma", "No-cache");
        res.addHeader("Cache-Control", "no-cache");
        res.addDateHeader("Expires", 1);

* Note that the expires header uses one instead of zero.  I have
  heard that some browsers have a problem respecting the value
  created by a zero date header.

Craig McClanahan
Yun Sang Jung wrote:


I implemented my first nocache tag. There is no error in compile and run
But my code seems not to work properly. If there is taglib code guru,
please tell me
how to correct my code..


[my Code]
import javax.servlet.http.*;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;


public class NoCacheTag extends TagSupport {
 public int doStartTag() throws JspException {
  return SKIP_BODY;

 public int doEndTag() throws JspException {
  HttpServletRequest req = (HttpServletRequest)
  HttpServletResponse res = (HttpServletResponse)

  if(req.getProtocol().compareTo ("HTTP/1.0") == 0) {
   res.setHeader ("Pragma", "no-cache");
  } else if (req.getProtocol().compareTo ("HTTP/1.1") == 0) {
   res.setHeader ("Cache-Control", "no-cache");
  res.setDateHeader ("Expires", 0);
  return EVAL_PAGE;

View raw message