"Williams, Stephen" wrote:
>
> I'd like to have all of my JSP pages execute a certain chunk of Java code
> before the page is displayed, and then execute another chunk of Java code
> after the page is displayed.  I could use an "include" at the top and bottom
> of each of my JSP pages, but this seems a little kludgy and error-prone.
> Another way to do this might be to have all my JSPs extend a subclass of
> HttpJspPage that I create.  However, I'm wary of doing this because Sun's
> JSP documentation states that extending the JSP page "limits the JSP
> container's ability to provide a specialized superclass that improves the
> quality of the compiled file."
>
> Does anyone have any experience with extending JSP pages through the use of
> the "page extends" directive?  If so, what advice do you have for someone
> thinking about doing it (e.g., gotchas, benefits)?
>
> Alternatively, has anyone created a workaround for extending the JSP page
> that accomplishes the same thing.

One way I can think of is to use a common "wrapper" JSP page that includes
the before and after stuff, plus the real JSP page, e.g.

  <jsp:include page="before.jsp" flush="true" />
  <jsp:include page="<%= request.getParameter("mainJSP") %>" flush="true" />
  <jsp:include page="after.jsp" flush="true" />

Or, maybe better, just let the "wrapper" JSP page contain the stuff
from "before.jsp" and "after.jsp" and only include the main page.

With something like this, all your JSP requests must use URIs like

  view.jsp?mainJSP=foo.jsp

where "view.jsp" is the wrapper page.

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

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

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to