• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

startup class in websphere5.0

I need to provide email, when the websphere app.server starts first time. I would appreciate if anybody send me class file and how to do settings on application server.

1 Solution
If you have your web application then the easy way to do is it
-- Write a class say SendMailAtStartUp.java which has public method say sendMail() which uses java mail api to send mail
-- Write a servlet.and 'make instance of the above class' and 'call the sendmail method()' in the init() method.
-- Register your servlet in web.xml.

Doing this, when the servlet is loaded by the web container for the first time, init() method would be invoked and the mail would be sent.
Another way is to use add a ServletContextListener, this listener will execute when server startup and shutdown.

First extend the class ServletContextListener. example:

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class StartupServletContextListener implements ServletContextListener {
       * @see javax.servlet.ServletContextListener#contextInitialized(ServletContextEvent)
      public void contextInitialized(ServletContextEvent arg0) {
        //put send mail function here.

       * @see javax.servlet.ServletContextListener#contextDestroyed(ServletContextEvent)
      public void contextDestroyed(ServletContextEvent arg0) {

Then add the the listener class to the web.xml
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now