⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foreachrowtag.java

📁 JSP学习的好东东
💻 JAVA
字号:
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.sql.*;
import java.util.*;

public class ForEachRowTag extends BodyTagSupport
{
	private ConnectTag ct;
	public int doStartTag() throws JspException
	{
		ct = (ConnectTag)findAncestorWithClass(this,ConnectTag.class);
		if( ct == null){
			throw new JspException("In [ForEachRow]:No ConnectTag Object error.");
		}	
		System.out.println("ForEachRowTag.doStartTag()......");
		return incrementRow();
	}
	public int doAfterBody() throws JspException
	{
		System.out.println("ForEachRowTag.doAfterBody()......");
		return incrementRow();		
	}
	private int incrementRow() throws JspException
	{
		ResultSet rs = ct.getResultSet();
		if(rs == null ){
			throw new JspException("No resultset.");
		}
		boolean hasNext;
		try{
			hasNext = rs.next();
		}catch(SQLException e){
			throw new JspException(e.getMessage());
		}
		System.out.println("ForEachRowTag.incrementRow()......");
		if(hasNext){
			return EVAL_BODY_TAG;
	 	}else{
	 		return SKIP_BODY;
	 	}
	}
	public int doEndTag() throws JspException
	{
		try{
			pageContext.getOut().print(bodyContent.getString());	
		}catch(IOException e){
			throw new JspException(e.getMessage());
		}
		System.out.println("ForEachRowTag.doEndTag()......");
		return EVAL_PAGE;	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -