Discussion:
Filters and load-on-startup
Blanchard, Raphael
2004-03-16 14:25:24 UTC
Permalink
Do filters get loaded before servlets regardless of load-on-startup value?

Raphael
Shapira, Yoav
2004-03-16 14:27:34 UTC
Permalink
Hi,
Post by Blanchard, Raphael
Do filters get loaded before servlets regardless of load-on-startup
value?

I don't think so: as filters can be mapped to servlet-name, servlets
must be loaded first. (Although I suppose you could read web.xml, so
you have the servlet info, then instantiance filters, then instantiate
servlets, but tomcat doesn't do this).

I wouldn't rely on this order unless you had to, however, as it's not
mandated either way by the Servlet Specification.

Yoav Shapira



This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you.
Ronald Wildenberg
2004-03-16 14:45:02 UTC
Permalink
Post by Shapira, Yoav
Hi,
Post by Blanchard, Raphael
Do filters get loaded before servlets regardless of load-on-startup
value?
I don't think so: as filters can be mapped to servlet-name, servlets
must be loaded first. (Although I suppose you could read web.xml, so
you have the servlet info, then instantiance filters, then instantiate
servlets, but tomcat doesn't do this).
I wouldn't rely on this order unless you had to, however, as it's not
mandated either way by the Servlet Specification.
Actually, it is. SRV9.12 mandates the following load order: listeners,
filters, servlets (Servlet Specification 2.4). So any filters should be
loaded before any servlets, regardless of load-on-startup value.


Regards, Ronald.
Shapira, Yoav
2004-03-16 14:49:14 UTC
Permalink
Hi,
Post by Ronald Wildenberg
Actually, it is. SRV9.12 mandates the following load order: listeners,
filters, servlets (Servlet Specification 2.4). So any filters should be
loaded before any servlets, regardless of load-on-startup value.
Yup, clear as day, thanks. I figured you'd have looked at the spec
before posting and then answering your own question?! ;)

Yoav Shapira



This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you.
Blanchard, Raphael
2004-03-16 15:05:31 UTC
Permalink
Actually I asked the question. Problem is I don't want the filter to be
loaded first. I'm trying to implement a webapp-wide connection pool to
mysql as documented in "Java Servlet's Developper's guide". I have a class
'ConnectionServlet' that is creates and initializes the connection pool.
The webapp has a login filter that needs a connection from the connection
pool. The webapp loads the login filter first. I don't really want to
remove the filter because its integral to the application's design. Is
there another solution, to getting the connection pool instantiated before
the filter?

Raphaƫl

-----Original Message-----
From: Shapira, Yoav [mailto:***@mpi.com]
Sent: Tuesday, March 16, 2004 10:49 AM
To: Tomcat Users List
Subject: RE: Filters and load-on-startup



Hi,
Post by Ronald Wildenberg
Actually, it is. SRV9.12 mandates the following load order: listeners,
filters, servlets (Servlet Specification 2.4). So any filters should be
loaded before any servlets, regardless of load-on-startup value.
Yup, clear as day, thanks. I figured you'd have looked at the spec
before posting and then answering your own question?! ;)

Yoav Shapira



This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential, proprietary
and/or privileged. This e-mail is intended only for the individual(s) to
whom it is addressed, and may not be saved, copied, printed, disclosed or
used by anyone else. If you are not the(an) intended recipient, please
immediately delete this e-mail from your computer system and notify the
sender. Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-***@jakarta.apache.org
For additional commands, e-mail: tomcat-user-***@jakarta.apache.org
Christopher Schultz
2004-03-16 17:02:10 UTC
Permalink
Raphael,
Post by Blanchard, Raphael
The webapp has a login filter that needs a connection from the connection
pool. The webapp loads the login filter first. I don't really want to
remove the filter because its integral to the application's design. Is
there another solution, to getting the connection pool instantiated before
the filter?
Is this really a problem? Even though the filter needs a DB connection
to do it's work, it doesn't need that connection until it's time to
actually /do/ work, right?

You're certainly not going to get a request processed before the
servlets are loaded, so it's probably alright that the DBCP is
initialized *after* the filter itself.

Oh, and Yoav is right: you really want a ServletContextListener, rather
than an 'init' servlet.

-chris

Shapira, Yoav
2004-03-16 15:12:04 UTC
Permalink
Hi,
Post by Blanchard, Raphael
Actually I asked the question. Problem is I don't want the filter to
be
Post by Blanchard, Raphael
loaded first. I'm trying to implement a webapp-wide connection pool to
mysql as documented in "Java Servlet's Developper's guide". I have a
class
Post by Blanchard, Raphael
'ConnectionServlet' that is creates and initializes the connection
pool.
Post by Blanchard, Raphael
The webapp has a login filter that needs a connection from the
connection
Post by Blanchard, Raphael
pool. The webapp loads the login filter first. I don't really want to
remove the filter because its integral to the application's design.
Is
Post by Blanchard, Raphael
there another solution, to getting the connection pool instantiated
before
Post by Blanchard, Raphael
the filter?
Double oops for me ;)

Yes there's another, better solution: use a ServletContextListener to
initialize your connection pool. As specified in the SRV location from
Senor Wildenberg, this will get called before any filters and servlets.

Yoav Shapira




This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you.
Loading...