tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Rudnicki <jdr5l...@pacbell.net>
Subject Re: Q:How to auto-execute a function everytime a servlet is invoked.
Date Tue, 02 May 2000 05:15:18 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:

Just a small cleanup here.
Like this works if the wrapper action is the same for any type of request.

 public class MyHttpServlet extends HttpServlet {

  public void service( ServletRequest req, ServletResponse res ) {
   domyaction();
   super.service(req, res);
   domyotheraction();
  }
}

The above would be fine approach if you want to count hits or similar.  Any
actions that do not manipulate the req or res I would opine are fine to wrap
using an overriden service().

But, I would not use it if you want to add headers and footers to the
response or similar.  If the ServletResponse was already modified when a
derived servlet received "res", I would prefer my approach.  It is more
clear that the servlet is not actually handling a doPost(), but only the
center part of it (via innerDoPost() ).  The approach I described also works
if you need to implement different behaviors for PUT, GET, and POST.  Don't
peek into the "req" and put a switch in the service().

bye,
Jim



Mime
View raw message