tabletag.java
来自「J2EE 技术 源码 书籍源代码(j2ee编程技术)」· Java 代码 · 共 82 行
JAVA
82 行
package tag;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class TableTag extends BodyTagSupport {
private int row;
private int col;
private ArrayList content;
/**
* @return Returns the col.
*/
public int getCol() {
return col;
}
/**
* @param col The col to set.
*/
public void setCol(int col) {
this.col = col;
}
/**
* @return Returns the row.
*/
public int getRow() {
return row;
}
/**
* @param row The row to set.
*/
public void setRow(int row) {
this.row = row;
}
public int doEndTag() {
content=(ArrayList)pageContext.getAttribute("content");
System.out.println("content size="+Integer.toString(content.size()));
try {
//使用JSPWriter获得JSP的输出对象
JspWriter JSPWriterOutput = pageContext.getOut();
String temp=new String();
for(int i=0;i<row;i++){
temp+="<tr>";
for(int j=0;j<col;j++){
String value=(String)content.get(i*col+j);
temp+="<td>"+value+"</td>";
}
temp+="</tr>";
}
JSPWriterOutput.println("<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\">" +temp+
"</table>");
} catch (IOException ioEx) {
System.out.println("IOException in TableTag " + ioEx);
}
return (SKIP_BODY);
}
public void release( ){
row = 0;
col =0;
content =null;
}// release
/**
* @return Returns the content.
*/
public ArrayList getContent() {
return content;
}
/**
* @param content The content to set.
*/
public void setContent(ArrayList content) {
this.content = content;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?