Easier still, you don't have to write a servlet, just a class that 
implements ServletContextListener, eg something like:

public class StartupListener implements ServletContextListener {
        private Log log = LogFactory.getLog(StartupListener.class);
        ServletContext servletContext;

        public void contextInitialized(ServletContextEvent sce) {
                servletContext = sce.getServletContext();

                // run your startup code in here!
        }

        // implement other methods here

}

How simple is that!

Brian

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: 15 October 2003 12:12
To: [EMAIL PROTECTED]
Subject: RE: Converting to Struts, where to put Servlet init() code?

You dont need to subclass the action servlet just for the init code...

Write u r own servlet(InitializationServlet)and put it in the init
method of this servlet.

When configuring the servlets in web.xml have somethign like this.

<servlet>
        <servlet-name>InitializationServlet</servlet-name>
        <display-name>InitializationServlet</display-name>
        <servlet-class>com.urapp.InitializationServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    And for all other servlets , the load-on-startupvalue should be
greater than 1.This ensures that when the servlets are
initialized(Loaded), the initialization servlet is loaded first which
means also the init method will be called before any requests are
received.


Additionally u can have any startup code called from the init method of
this servlet.

Hope this helps.
Regards,
Shirish

-----Original Message-----
From: Mark Galbreath [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 15, 2003 2:04 PM
To: Struts Users Mailing List
Subject: RE: Converting to Struts, where to put Servlet init() code?


subclass ActionServlet and put your inits there.

-----Original Message-----
From: Wendy Smoak [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 14, 2003 7:43 PM
To: [EMAIL PROTECTED]
Subject: Converting to Struts, where to put Servlet init() code?



I'm converting an existing webapp to Struts.  I have some code in a
Servlet init() method, and I don't immediately see where I should put
it.  This is an authentication/authorization webapp, and the code in
question sets up an authentication handler object to be used by every
subsequent request.

What's guaranteed to get executed before the Action code?  (I'm almost
thinking Filter, and to put the object in Application scope, but I'm not
sure yet.)

Any advice?

-- 
Wendy Smoak
Applications Systems Analyst, Sr.
Arizona State University, PA, IRM 

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




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


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


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

Reply via email to