0 Replies Latest reply on Jul 25, 2005 2:10 AM by Subhash Kurni

    HTTPSESSION LISTENER

    Subhash Kurni Newbie

      Hi...

      I am working on JBOSS AS v4.

      I have deployed an ear file and is working perfectly...the ear package contains the ejb.jar and web.war packages.In the web.war package we have web-inf inside which we have web.xl file.Here the xml is like this

      <?xml version = '1.0' encoding = 'windows-1252'?>
      <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
      <web-app>
      <display-name>Web XML</display-name>
      EXAMPLEption>
      <session-config>
      <session-timeout>30</session-timeout>
      </session-config>
      <mime-mapping>
      html
      <mime-type>text/html</mime-type>
      </mime-mapping>
      <mime-mapping>
      txt
      <mime-type>text/plain</mime-type>
      </mime-mapping>
      <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>index.html</welcome-file>
      </welcome-file-list>
      <resource-ref>
      eCom Database Connection Data Source
      <res-ref-name>jdbc/eComDataSource</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>

      <listener-class>com.dcons.eCom.client.SessionListen</listener-class>

      </resource-ref>
      <ejb-ref>
      Logging EJB
      <ejb-ref-name>LogWriter</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      com.dcons.eCom.ejb.LogWriterHome
      com.dcons.eCom.ejb.LogWriter
      <ejb-link>LogWriter</ejb-link>
      </ejb-ref>
      <ejb-ref>
      LoginHandler
      <ejb-ref-name>LoginHandler</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      com.dcons.eCom.ejb.LoginHandlerHome
      com.dcons.eCom.ejb.LoginHandler
      <ejb-link>LoginHandler</ejb-link>
      </ejb-ref>
      <ejb-ref>
      SessionFacade
      <ejb-ref-name>SessionFacade</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      com.dcons.eCom.ejb.SessionFacadeHome
      com.dcons.eCom.ejb.SessionFacade
      <ejb-link>SessionFacade</ejb-link>
      </ejb-ref>

      <servlet-name>Controller</servlet-name>
      <jsp-file>Controller.jsp</jsp-file>

      <servlet-mapping>
      <servlet-name>Controller</servlet-name>
      <url-pattern>/Controller</url-pattern>
      </servlet-mapping>
      </web-app>


      My SessionListen doesnt invoke at all,,,I donno how to invoke this sessionlisten servlet...I am suppose to capture whenever the user seeion is created or destroyed,,plz let me know how and where to configure this servlet..the SessionLIsten is as follows..


      import java.util.Date;

      import javax.servlet.http.HttpSession;
      import javax.servlet.http.HttpSessionEvent;
      import javax.servlet.http.HttpSessionListener;

      public class SessionListen implements HttpSessionListener {

      private int sessionCount;

      public SessionListen() {
      this.sessionCount = 0;
      }

      public void sessionCreated(HttpSessionEvent se) {
      HttpSession session = se.getSession();
      session.setMaxInactiveInterval(60);
      synchronized (this) {
      sessionCount++;
      }
      String id = session.getId();
      Date now = new Date();
      String message = new StringBuffer("New Session created on ").append(
      now.toString()).append("\nID: ").append(id).append("\n")
      .append("There are now ").append("" + sessionCount).append(
      " live sessions in the application.").toString();

      System.out.println(message);
      }

      public void sessionDestroyed(HttpSessionEvent se) {

      HttpSession session = se.getSession();
      String id = session.getId();
      synchronized (this) {
      --sessionCount;
      }
      String message = new StringBuffer("Session destroyed"
      + "\nValue of destroyed session ID is").append("" + id).append(
      "\n").append("There are now ").append("" + sessionCount)
      .append(" live sessions in the application.").toString();
      System.out.println(message);
      }
      }

      U can contact me at i_subhash@yahoo.com

      Regds
      Subhash.K