Initializing Servlets

S

Scott Harper

I've been going through Sun's J2EE tutorial, and I realize that its goal is to
show as many examples as possible, which leads to the following question:

What is the relationship of the ServletContextListener and the
contextInitialized/contextDestroyed events to the servlet's init() and
destroy() methods? Is it a purely 1:1 relationship? I.e. every time a
contextInitialized event gets set to the listener, exactly one call to the
servlet's init() method can be expected?

If so, what are the considerations for using one or the other mechanism to
initialize context-global data?

In my case, I want to open a file that is available for any servlet thread to
write to, and close it when the servlet is destroyed. Can't I do that in the
init() and destroy() methods?


scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,223
Latest member
Jurgen2087

Latest Threads

Top