Return-Path: Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 40473 invoked from network); 1 May 2000 07:19:01 -0000 Received: from mta5.snfc21.pbi.net (206.13.28.241) by locus.apache.org with SMTP; 1 May 2000 07:19:01 -0000 Received: from jdr5 ([216.101.184.151]) by mta5.snfc21.pbi.net (Sun Internet Mail Server sims.3.5.2000.01.05.12.18.p9) with SMTP id <0FTV0043MDNBEA@mta5.snfc21.pbi.net> for tomcat-user@jakarta.apache.org; Mon, 1 May 2000 00:18:48 -0700 (PDT) Date: Mon, 01 May 2000 00:20:16 -0700 From: Jim Rudnicki Subject: Re: Q:How to auto-execute a function everytime a servlet is invoked. To: tomcat-user@jakarta.apache.org Message-id: <00b201bfb33d$b349d300$3301a8c0@pacbell.net> MIME-version: 1.0 X-Mailer: Microsoft Outlook Express 5.00.2919.6600 Content-type: text/plain; charset="iso-8859-1" Content-transfer-encoding: 7bit X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 References: <20000428235801.54895.qmail@hotmail.com> X-Priority: 3 X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N Rishi, I believe I understand what you want class TrackedServlet extends HttpServlet { public void doGet( HttpServletRequest request, HttpServletResponse response ) { do common action call doGet() in DerivedServlet do common action. } } class DerivedServlet extends TrackedServlet { public void doGet( HttpServletRequest request, HttpServletResponse response ) { create page } } You want Tomcat to call TrackedServlet.doGet, which in turn would execute the DerivedServlet doGet(). The effect is wrapping the derived class behavior with that in the base class. The language won't support this. Tomcat will always see the derived class method. C++ templates would allow a solution, but I have another good solution. My advice: think simple. abstract class TrackedServlet extends HttpServlet { protected abstract void innerDoGet( HttpServletRequest request, HttpServletResponse response ) ; protected abstract void innerDoPost( HttpServletRequest request, HttpServletResponse response ) ; public void doGet( HttpServletRequest request, HttpServletResponse response ) { /* do common action */ innerDoGet(request, response); /* do common action. */ } } class DerivedServlet extends TrackedServlet { public void innerDoGet( HttpServletRequest request, HttpServletResponse response ) { /* create page */ } public void innerDoPost( HttpServletRequest request, HttpServletResponse response ) { /* create page */ } } I believe this is the only correct way to shim code before and after the calls to doGet() or doPost(). A developer only has to know to derive the servlet from TrackedServlet and implement the abstract methods. I agree, the jsp soln is _____(deleted). gnite, Jim ----- Original Message ----- From: "Rishi N" To: Sent: Friday, April 28, 2000 4:58 PM Subject: Re: Q:How to auto-execute a function everytime a servlet is invoked . > > > > >Hi, > >For JSP you could use the "extends" directive but it would be > >far easier to use a bean or just include another JSP page > >at runtime that does the update. > > > > > >which will include it at runtime? > > > >Greg > > > >Rishi N wrote: > > > > > > hi, > > > > > > i tried overwriting just the service method. so my service method runs > >my > > > function, and then i just call super.service(req,res), to invoke the > > > HttpServlet version of service.this seems to work fine. i think i don't > >need > > > to overwrite any of the other methods. is this correct? please advise. > > > > > > i also have another problem now. the above trick will work for servlets, > >but > > > how can i handle jsp's? i have no control over how the corresponding > > > servlets are generated, so i cannot make them extend my class. of > >course, i > > > could probably modify the tomcat code to make sure they use my servlet, > >but > > > that seems to be a very dirty hack. is there any other way of doing > >this? > > > > > > thanks, > > > risi