Tiana Zhang wrote:
>
> Hi,
>
> I'm trying to overwrite the jspDestroy() method to clean up files generated by
> my jsp pages. Can anyone tell me how to do this and where to put the method?
>
> I added a method in jsp page:
> <%! public void jspDestroy() {
>
> Httpsession session = request.getSession();
> new File((String)session.getValue("outfile1")).delete();
> new File((String)session.getValue("outfile2")).delete();
> }
>
> %>
>
> The compiler complains unrecognized variable "request".
The jspDestroy() method is only called when the JSP container is shut down,
not after processing each request as you seem to believe. It doesn't have
access to any of the implicit JSP objects (since they are local variables
in the _jspService() method.
I have a feeling you're trying to use the wrong mechanism for your needs.
If you need to clean up at the end of processing the request, add the code
as scriptlets (or in a custom action) at the end of the page. Note, however,
that if you forward to another page from this page, the code after <jsp:forward>
is not executed. Same thing is something in the page results in an error,
so the request is automatically forwarded to an error page.
If you need to clean up when a session ends, put an object in the session
that implements the HttpSessionBindingListener interface. It will be called
when the session ends to let you do the clean up.
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