Re: Servlet filter and listerner best practices

2003-02-21 Thread Will Hartung
 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]




RE: Servlet filter and listerner best practices

2003-02-21 Thread Etienne
Thanks Will, 

The filter servlet is only for logging checking and parameter init. I
would have like to learn more about (J2EE) pattern using filter and
listener servlet.

The problem about the filter servlet is that doFilter() do not throws
exception, so we must catch everything in doFilter. So that is why I was
hiding everything in back of it. It can be hard to debug that way.

Regards, 

Etienne


-Original Message-
From: Will Hartung [mailto:willh@x] 
Sent: February 21, 2003 12:36 PM
To: Tomcat Users List
Subject: Re: Servlet filter and listerner best practices

 From: Etienne etienno@
 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
(willh@x)





-
To unsubscribe, e-mail: tomcat-user-unsubscribe@xx
For additional commands, e-mail: tomcat-user-help@xx



-
To unsubscribe, e-mail: tomcat-user-unsubscribe@xx
For additional commands, e-mail: tomcat-user-help@xx



Re: Servlet filter and listerner best practices

2003-02-21 Thread Will Hartung
 From: Etienne etienno@
 Sent: Friday, February 21, 2003 11:06 AM
 Subject: RE: Servlet filter and listerner best practices


 Thanks Will,

 The filter servlet is only for logging checking and parameter init. I
 would have like to learn more about (J2EE) pattern using filter and
 listener servlet.

Logging is pretty simple, as you simply Do Your Thing either before or after
the doFilter call (or both). Here the Filter is a simple wrapper.

I think they're handy for doing the parameter parsing and creating a local
instance of a specific Parameter class that your code relies on. This helps
loosen up the binding between your logic and the fact that it's buried in a
Servlet container. Of course, you still need to pass in the Parameter, I
stuff it into the Request as an attribute.

 The problem about the filter servlet is that doFilter() do not throws
 exception, so we must catch everything in doFilter. So that is why I was
 hiding everything in back of it. It can be hard to debug that way.

Well, it can throw a ServletException, which is the same as the
Servlet.service() method, though service() also can throw an IOException, so
you're really not losing anything.

Mind I'm not saying that it can't be limiting, but it's just not that much
more limiting than the normal happenings within Servlet programming.

Regards,

Will Hartung
(willh@x)




-
To unsubscribe, e-mail: tomcat-user-unsubscribe@xx
For additional commands, e-mail: tomcat-user-help@xx