当前页面: 开发资料首页 → J2EE 专题 → 深入理解SKIP_PAGE, EVAL_PAGE
摘要: EVAL_PAGE不就是在doEndTag的时候返回的值麻. 恩... 看看Tomcat的source...EVAL_PAGE是指不销毁(交给Garbage Collection)而是放回池中回收利用. 这样他的生命期就会延长到整个页面load结束....
/**
* Skip the rest of the page.
* Valid return value for doEndTag.
*/
public final static int SKIP_PAGE = 5;
/**
* Continue evaluating the page.
* Valid return value for doEndTag().
*/
public final static int EVAL_PAGE = 6;
private boolean _jspx_meth_jzk_TagTest_2(PageContext _jspx_page_context)
throws Throwable {
JspWriter out = _jspx_page_context.getOut();
// jzk:TagTest
org.jzk.taglib.TagTest _jspx_th_jzk_TagTest_2 = (org.jzk.taglib.TagTest) _jspx_tagPool_jzk_TagTest_testAttr.get(org.jzk.taglib.TagTest.class);
_jspx_th_jzk_TagTest_2.setPageContext(_jspx_page_context);
_jspx_th_jzk_TagTest_2.setParent(null);
_jspx_th_jzk_TagTest_2.setTestAttr("test");
int _jspx_eval_jzk_TagTest_2 = _jspx_th_jzk_TagTest_2.doStartTag();
if (_jspx_th_jzk_TagTest_2.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return true;
_jspx_tagPool_jzk_TagTest_testAttr.reuse(_jspx_th_jzk_TagTest_2);
return false;
}
if (_jspx_th_jzk_TagTest_2.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return true;
private int i = 0;
public int doEndTag() throws JspException {
i++;
try {
pageContext.getResponse().getWriter().print(i + "
");
} catch (IOException e) {
//...
}
return EVAL_PAGE;
}
org.jzk.taglib.TagTest
/*
* Created on 2005-4-17
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.jzk.taglib;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
/**
* @author Jzk
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class TagTest extends TagSupport {
private String testAttr;
private int i = 0;
/*
* (non-Javadoc)
*
* @see javax.servlet.jsp.tagext.Tag#doEndTag()
*/
public int doEndTag() throws JspException {
i++;
try {
pageContext.getResponse().getWriter().print(i + "
");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return EVAL_PAGE;
}
/*
* (non-Javadoc)
*
* @see javax.servlet.jsp.tagext.Tag#doStartTag()
*/
public int doStartTag() throws JspException {
try {
pageContext.getResponse().getWriter().write(testAttr);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return super.doStartTag();
}
/**
* @return Returns the testAttr.
*/
public String getTestAttr() {
return testAttr;
}
/**
* @param testAttr
* The testAttr to set.
*/
public void setTestAttr(String testAttr) {
this.testAttr = testAttr;
}
}
<?xml version="1.0" encoding="UTF-8"?>
taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">1.0 1.1 bean jzk/tag TagTest org.jzk.taglib.TagTest testAttr false true