Is is possible to conditionally output some text in a JSP custom tag body? I'd like to be able to, on the first loop of the JSP custom tag body, add a line of text to the top of the body, than for each successive loop of the JSP custom tag body, output the text without the added line.

Christopher Pickslay

Sure. Put the code that writes your "items returned" header in your doStartTag() method. This way, it will only get called whenever you have an <info:x> tag. So your doStartTag() method will look something like this (exception handling removed for clarity):

public int doStartTag() throws JspTagException {
  // get data 
  ResultSet rs = ...;
  // get number of rows returned by moving to the end of the ResultSet and checking the row number
  int numItems = rs.getRow();
  // get surrounding JSPWriter
  JSPWriter out = getPreviousOut();
  // write header
  out.println("Items Returned: " + numItems);
  // evaluate body
  return EVAL_BODY_TAG;
Note that you'll have to have the data (number of rows returned) available by the time this is called, so your database access code will have to be in doStartTag(), or in a bean that's accessible by your taglib code.