> From: "Etienne" <[EMAIL PROTECTED]>
> Sent: Friday, February 21, 2003 3:47 AM
> Subject: Servlet filter and listerner best practices


> Hi all,
>
> I am looking for some "best practices" for servlet filter (and servlet
> listener). These are quite new (servlet 2.3). I am using a servlet
> filter on some of my jsp page, but I would need a detail example of the
> best way to implement it.

It kind of all depends on what your Filter needs to do. Passive filters
(like, say, a Logging Filter) can be quite different from something like a
GZip filter, which needs to really muck about with the request and streams
and what not.

> I am not sure how to catch exception in the servlet filter without hiding
> everything in the back on it.

Pretty standard exception technique here. If you catch an exception that you
don't want to deal with, simply throw it again and let something else higher
up take care of it. Even better, don't catch exceptions that you can't
handle at all. The old proclamation of "Don't test for something you can't
handle" rings loudly here.

Perhaps some more detail about your situation would be helpful.

> Is there a more precise way (with some reg ex?) to associate a filter with
pages?

I dunno, the filter specification is pretty specific, perhaps too specific
meaning that for lots of disparate pages, you'll have lots of entries in the
web.xml. Perhaps if you could organize your pages in a hierarchy so you
could simply put the filter on a parent directory part of the path would
help reduce the load on the web.xml file.

Regards,

Will Hartung
([EMAIL PROTECTED])





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to