tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rishi N" <rea...@hotmail.com>
Subject Re: Q:How to auto-execute a function everytime a servlet is invoked.
Date Mon, 01 May 2000 12:32:48 GMT
Hi Jim,

thanks for your suggestion. actually, since i'm just beginning to use 
servlets(and even java, for that matter!), i didn't really think in all the 
detail that you did. basically i want to continue using the default servlet 
service-handling behaviour, but execute certain actions before and after 
that behaviour. so this is what i'm thinking of doing:

public class myhttpservlet extend HttpServlet(Req, Res)
{
domyaction();
super.service(Req.res);
domyotheraction;
}


then all my servlets extend  myhttpservlet.

please advise if this approach has any pitfalls.
thanks,
rishi


>From: Jim Rudnicki <jdr5list@pacbell.net>
>Reply-To: tomcat-user@jakarta.apache.org
>To: tomcat-user@jakarta.apache.org
>Subject: Re: Q:How to auto-execute a function everytime a servlet is 
>invoked.
>Date: Mon, 01 May 2000 00:20:16 -0700
>MIME-Version: 1.0
>Received: from [63.211.145.10] by hotmail.com (3.2) with ESMTP id 
>MHotMailBAD67AED006DD82197DB3FD3910A0A520; Mon May 01 00:19:09 2000
>Received: (qmail 40480 invoked by uid 500); 1 May 2000 07:19:01 -0000
>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)
>From tomcat-user-return-2046-reache Mon May 01 00:19:36 2000
>Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm
>Precedence: bulk
>X-No-Archive: yes
>list-help: <mailto:tomcat-user-help@jakarta.apache.org>
>list-unsubscribe: <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>list-post: <mailto:tomcat-user@jakarta.apache.org>
>Delivered-To: mailing list tomcat-user@jakarta.apache.org
>Message-id: <00b201bfb33d$b349d300$3301a8c0@pacbell.net>
>X-Mailer: Microsoft Outlook Express 5.00.2919.6600
>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" <reache@hotmail.com>
>To: <tomcat-user@jakarta.apache.org>
>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.
> > >
> > ><jsp:include page="update.jsp" flush="true"/>
> > >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
>
>
>
>--------------------------------------------------------------------------
>To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commmands, email: tomcat-user-help@jakarta.apache.org
>

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


Mime
View raw message