Yes, there are two ways I know of.  The best way is to write a tag that does
this for you.  In other words:

<a:cache id="thispage.jsp_js1" timetolive="200">
  <%-- any arbitrary JSP/HTML/JavaScript here --%>
</a:cache>

Capturing the output is quite easy to do if you're familiar with writing
tags.  Just extend BodyTagSupport, and in the doAfterBody() call
bodyContent.getString().  (The harder part will be the actual
caching--making sure it works properly when multithreaded, etc.  But I bet
you can find lots of good caching implementations on the web.)

The second way is to just use JSP to hack it.  In fact, since your rendered
JavaScript is not going to change over time, you could probably just do
this.

<%! private static String jScriptOutput = null; %>
<%
if (jScriptOutput != null) {
  out.print(jScriptOutput);
} else {
  javax.servlet.jsp.tagext.BodyContent bc = pageContext.pushBody();
  out = bc;
%>

  <%-- any arbitrary JSP/HTML/JavaScript here --%>

<%
  out = pageContext.popBody();
  jScriptOutput = bc.getString();
  out.print(jScriptOutput);
}
%>

Either of these methods is going to require at least JSP 1.1 / Servlet 2.2,
I believe (i.e. Tomcat 3.x).

-jmc

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to