1. Foreword In order to understand the origin of this framework, we first look at the content of the Java file that the JSP parser converts to our JSP code. Below is a JSP file test.jsp the Java file that is converted by Tomcat Test$jsp.java the following: package org.apache.jsp; Import javax.servlet.*; Import javax.servlet.http.*; Import javax.servlet.jsp.*; Import org.apache.jasper.runtime.*; public class Test$jsp extends Httpjspbase { static { }   &NB Sp Public testoutredir$jsp () { } private static Boolean _jspx_inited = false; public final void _jspx_init () throws Org.apache.jasper.runtime.JspException { & nbsp } public void _jspservice (HttpServletRequest request, httpservletresponse Response) & nbsp; throws Java.io.IOException, servletexception { jspfactory _jspxfactory = null; PageContext pagecontext = null; HttpSession session = NULL; ServletContext application = null; servletconfig config = null; JspWriter out = null; Object page = this; string _value = null; try { if (_jspx_inited = False) { synchronized (this) { if (_jspx_inited = False) { _jspx_init (); _jspx_inited = true; } } } _jspxfactory = Jspfactory.getdefaultfactory (); Response.setcontenttype (text/html;charset= GB2312); PageContext = _jspxfactory.getpagecontext (This , request, response, , True, 8192, true); application = Pagecontext.getservletcontext (); config = Pagecontext.getservletconfig (); session = Pagecontext.getsession (); out = Pagecontext.getout (); /To save space, I removed the annotation added by the interpreter Out.write (/r/n); The previous sentence is due to the subsequent line of Out.write (); Out.write (/r/n/r/n/r /n/r/n); out.print (output); Out.write (/r/n/r/n/r/n/r/n); } catch (Throwable t) { if (out!= null && out.getbuffersize ()!= 0) Out.clearbuffer (); if (PageContext!= null) Pagecontext.handlepageexception (t); } finally { if (_jspxfactory!= null) _jspxfactory.releasepagecontext (PageContext); } } from the above code, you can clearly see several objects built in the JSP (out, request, response, Session, PageContext, Application, config, page) is how to produce, know the servlet's friends can see it. The following is an important understanding of the Out object, which is declared as a jspwriter type, and JspWriter is an abstract class that can be found in the package javax.servlet.jsp.
Abstract PublicclassJavax.servlet.jsp.JspWriter extends Java.io.Writer{
final public static intNo_buffer = 0;
final public static intDefault_buffer =-1;
final public static intunbounded_buffer =-2;
protected intbuffersize;
protected BooleanAutoFlush;
protectedJavax.servlet.jsp.JspWriter (
intArg1,
BooleanARG2);
Abstract PublicvoidNewLine ()
throwsIOException;
Abstract PublicvoidPrint
BooleanARG0)
throwsIOException;
Abstract PublicvoidPrint
CharARG0)
throwsIOException;
Abstract PublicvoidPrint
intARG0)
throwsIOException;
Abstract PublicvoidPrint
LongARG0)
throwsIOException;
Abstract PublicvoidPrint
floatARG0)
throwsIOException;
Abstract PublicvoidPrint
DoubleARG0)
throwsIOException;
Abstract PublicvoidPrint
Char[] arg0)
throwsIOException;
Abstract PublicvoidPrint (String arg0)
throwsIOException;
Abstract PublicvoidPrint (Object arg0)
throwsIOException;
Abstract Publicvoidprintln ()
throwsIOException;
Abstract Publicvoidprintln
BooleanARG0)
throwsIOException;
Abstract Publicvoidprintln
CharARG0)
throwsIOException;
Abstract Publicvoidprintln
intARG0)
throwsIOException;
Abstract Publicvoidprintln
LongARG0)
throwsIOException;
Abstract Publicvoidprintln
floatARG0)
throwsIOException;
Abstract Publicvoidprintln
DoubleARG0)
throwsIOException;
Abstract Publicvoidprintln
Char[] arg0)
throwsIOException;
Abstract Publicvoidprintln (String arg0)
throwsIOException;
Abtract Publicvoidprintln (Object arg0)
throwsIOException;
Abstract PublicvoidClear ()
throwsIOException;
Abstract PublicvoidClearbuffer ()
throwsIOException;
Abstract PublicvoidFlush ()
throwsIOException;
Abstract PublicvoidClose ()
throwsIOException;
PublicintGetBufferSize ();
Abstract PublicintGetremaining ();
PublicBooleanIsautoflush (); I believe that when I write here you may already know what I want to do. Yes, a steal, inherits the JspWriter class, then implements its defined virtual function, and then replaces the out variable with an instance of your own implementation class. OK.
2. Implement ReplacementSuppose Out.close ();//Closes the generated static file Out_bak.clear ();p Agecontext.forward (FilePath); SYSTEM.OUT.PRINTLN (Run this page and go to static page);return-->
3. Update issues Here is a discussion of how to update the generation of static files, in fact, from the above implementation you can see, very simple is to create static files can be deleted, as to when to delete, depends on your needs. I can think of several situations as follows when you use to generate data updates for a page, data that is not required to provide time can be updated regularly and never updated.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.