package student.taglib; import javax.servlet.jsp.tagext.TagSupport; import java.sql.ResultSet; import student.DBBean; /** * put your documentation comment here */ public class GoodsHeaderTag extends TagSupport { public ResultSet resultset; String sqlstring; /** * put your documentation comment here */ public ResultHeaderTag () { resultset = null; sqlstring = "SELECT id,name,price,vendor FROM goods"; } /** * put your documentation comment here * @return */ public int doStartTag () { query(); return EVAL_BODY_INCLUDE; } /** * put your documentation comment here * @return */ public int doAfterBody () { try { if(resultset.isAfterLast()){ return SKIP_BODY;// 输出完毕则继续往下执行 }else{ resultset.next(); return EVAL_BODY_AGAIN;//还有未输出,重新对其body content计值 } } } catch (Exception e) { System.out.println(e.getMessage()); } return SKIP_BODY; } /** * put your documentation comment here * @return */ public int doEndTag () { try { resultset.close(); } catch (Exception e) { System.out.println(e.getMessage()); } return EVAL_PAGE; } public ResultSet query(){ DBBean dbbean = new DBBean(sqlstring); resultset = dbbean.query(); } }