1、客户端访问jsp页面,遇到自定义的标签;
2、初始化自定义标签对应的标签处理器,并通过setPageContext()方法,设置pageContext给标签对象;
3、看标签是否有父标签,如果有,则实例化父标签对应的处理器对象。并通过setParent()方法设置给标签对象;
4、调用doStartTag()方法
5、执行标签体
6、调用doEndTag()方法
7、释放资源
8、执行标签体后面的jsp相关的代码
以下是tomcat下面运行jsp后的java代码
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;
public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
private static java.util.List _jspx_dependants;
static {
_jspx_dependants = new java.util.ArrayList(1);
_jspx_dependants.add("/WEB-INF/simpletag/simple.tld");
}
private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.AnnotationProcessor _jsp_annotationprocessor;
public Object getDependants() {
return _jspx_dependants;
}
public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
}
public void _jspDestroy() {
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;
try {
response.setContentType("text/html;charset=ISO-8859-1");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\r\n");
out.write("\r\n");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
out.write("\r\n");
out.write("\r\n");
out.write("<html>\r\n");
out.write(" <head>\r\n");
out.write(" <title>My JSP 'index.jsp' starting page</title>\r\n");
out.write(" </head>\r\n");
out.write(" \r\n");
out.write(" <body>\r\n");
out.write(" ");
String ip = request.getRemoteAddr();
out.print(ip);
out.write('\r');
out.write('\n');
out.write(' ');
if (_jspx_meth_simple_005fsimple5_005f0(_jspx_page_context))
return;
out.write("\r\n");
out.write(" </body>\r\n");
out.write("</html>\r\n");
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
private boolean _jspx_meth_simple_005fsimple5_005f0(PageContext _jspx_page_context)
throws Throwable {
PageContext pageContext = _jspx_page_context;
JspWriter out = _jspx_page_context.getOut();
// simple:simple5
www.itcast.cn.Simple5 _jspx_th_simple_005fsimple5_005f0 = new www.itcast.cn.Simple5();
org.apache.jasper.runtime.AnnotationHelper.postConstruct(_jsp_annotationprocessor, _jspx_th_simple_005fsimple5_005f0);
_jspx_th_simple_005fsimple5_005f0.setJspContext(_jspx_page_context);
// /index.jsp(18,1) name = name type = null reqTime = true required = true fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
_jspx_th_simple_005fsimple5_005f0.setName(9);
_jspx_th_simple_005fsimple5_005f0.setJspBody(new index_jspHelper( 0, _jspx_page_context, _jspx_th_simple_005fsimple5_005f0, null));
_jspx_th_simple_005fsimple5_005f0.doTag();
org.apache.jasper.runtime.AnnotationHelper.preDestroy(_jsp_annotationprocessor, _jspx_th_simple_005fsimple5_005f0);
return false;
}
private class index_jspHelper
extends org.apache.jasper.runtime.JspFragmentHelper
{
private javax.servlet.jsp.tagext.JspTag _jspx_parent;
private int[] _jspx_push_body_count;
public index_jspHelper( int discriminator, JspContext jspContext, javax.servlet.jsp.tagext.JspTag _jspx_parent, int[] _jspx_push_body_count ) {
super( discriminator, jspContext, _jspx_parent );
this._jspx_parent = _jspx_parent;
this._jspx_push_body_count = _jspx_push_body_count;
}
public boolean invoke0( JspWriter out )
throws Throwable
{
out.write("fdfd");
return false;
}
public void invoke( java.io.Writer writer )
throws JspException
{
JspWriter out = null;
if( writer != null ) {
out = this.jspContext.pushBody(writer);
} else {
out = this.jspContext.getOut();
}
try {
this.jspContext.getELContext().putContext(JspContext.class,this.jspContext);
switch( this.discriminator ) {
case 0:
invoke0( out );
break;
}
}
catch( Throwable e ) {
if (e instanceof SkipPageException)
throw (SkipPageException) e;
throw new JspException( e );
}
finally {
if( writer != null ) {
this.jspContext.popBody();
}
}
}
}
}